Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Unpivot Example
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
--Sql Server 2014 Express Edition --Batches are separated by 'go' declare @temp table (vendor_id int, emp1 int, emp2 int, emp3 int, emp4 int, emp5 int); insert into @temp values (1,4,3,5,4,4); insert into @temp values (2,4,1,5,5,5); insert into @temp values (3,4,3,5,4,4); insert into @temp values (4,4,2,5,5,4); insert into @temp values (5,5,1,5,5,5); select * from @temp select vendor_id as VendorID, Employee, Orders from (select vendor_id,emp1,emp2,emp3,emp4,emp5 from @temp) as p unpivot( Orders for Employee in (emp1,emp2,emp3,emp4,emp5) ) as unpvt order by unpvt.Employee asc , unpvt.vendor_id asc
View schema
edit mode
|
history
|
discussion