| 1 |
select v,h,c from v_data \crosstabview |
| 2 |
-- |
| 3 |
v|h|c |
| 4 |
v1|h2|foo |
| 5 |
v2|h1|bar |
| 6 |
v1|h0|baz |
| 7 |
v0|h4|qux |
| 8 |
-- |
| 9 |
v|h2|h1|h0|h4 |
| 10 |
v1|foo||baz| |
| 11 |
v2||bar|| |
| 12 |
v0||||qux |
| 13 |
|
| 14 |
select v,h,c from v_data order by 1 \crosstabview v h c |
| 15 |
-- |
| 16 |
v|h|c |
| 17 |
v0|h4|qux |
| 18 |
v1|h2|foo |
| 19 |
v1|h0|baz |
| 20 |
v2|h1|bar |
| 21 |
-- |
| 22 |
v|h4|h2|h0|h1 |
| 23 |
v0|qux||| |
| 24 |
v1||foo|baz| |
| 25 |
v2||||bar |
| 26 |
|
| 27 |
select v,h,c from v_data order by 1 desc \crosstabview v h c |
| 28 |
-- |
| 29 |
v|h|c |
| 30 |
v2|h1|bar |
| 31 |
v1|h2|foo |
| 32 |
v1|h0|baz |
| 33 |
v0|h4|qux |
| 34 |
-- |
| 35 |
v|h1|h2|h0|h4 |
| 36 |
v2|bar||| |
| 37 |
v1||foo|baz| |
| 38 |
v0||||qux |
| 39 |
|
| 40 |
select v,h,c from v_data order by 2 \crosstabview v h c |
| 41 |
-- |
| 42 |
v|h|c |
| 43 |
v1|h0|baz |
| 44 |
v2|h1|bar |
| 45 |
v1|h2|foo |
| 46 |
v0|h4|qux |
| 47 |
-- |
| 48 |
v|h0|h1|h2|h4 |
| 49 |
v1|baz||foo| |
| 50 |
v2||bar|| |
| 51 |
v0||||qux |
| 52 |
|
| 53 |
select v,h,c,row_number() over(order by h) as hsort from v_data order by 1 \crosstabview v h c |
| 54 |
-- |
| 55 |
v|h|c|hsort |
| 56 |
v0|h4|qux|4 |
| 57 |
v1|h0|baz|1 |
| 58 |
v1|h2|foo|3 |
| 59 |
v2|h1|bar|2 |
| 60 |
-- |
| 61 |
v|h4|h0|h2|h1 |
| 62 |
v0|qux||| |
| 63 |
v1||baz|foo| |
| 64 |
v2||||bar |
| 65 |
|
| 66 |
select v,h,c,row_number() over(order by h) as hsort from v_data order by 1 \crosstabview v h c hsort |
| 67 |
-- |
| 68 |
v|h|c|hsort |
| 69 |
v0|h4|qux|4 |
| 70 |
v1|h0|baz|1 |
| 71 |
v1|h2|foo|3 |
| 72 |
v2|h1|bar|2 |
| 73 |
-- |
| 74 |
v|h0|h1|h2|h4 |
| 75 |
v0||||qux |
| 76 |
v1|baz||foo| |
| 77 |
v2||bar|| |
| 78 |
|
| 79 |
select v,h,c,row_number() over(order by h desc) as hsort from v_data order by 1 \crosstabview v h c hsort |
| 80 |
-- |
| 81 |
v|h|c|hsort |
| 82 |
v0|h4|qux|1 |
| 83 |
v1|h2|foo|2 |
| 84 |
v1|h0|baz|4 |
| 85 |
v2|h1|bar|3 |
| 86 |
-- |
| 87 |
v|h4|h2|h1|h0 |
| 88 |
v0|qux||| |
| 89 |
v1||foo||baz |
| 90 |
v2|||bar| |
| 91 |
|
| 92 |
select v,to_char(d,'Mon') as m, c from v_data order by 1 \crosstabview v m c |
| 93 |
-- |
| 94 |
v|m|c |
| 95 |
v0|Jul|qux |
| 96 |
v1|Apr|foo |
| 97 |
v1|Jul|baz |
| 98 |
v2|Jan|bar |
| 99 |
-- |
| 100 |
v|Jul|Apr|Jan |
| 101 |
v0|qux|| |
| 102 |
v1|baz|foo| |
| 103 |
v2|||bar |
| 104 |
|
| 105 |
select v,to_char(d,'Mon') as m, c from v_data order by d \crosstabview v m c |
| 106 |
-- |
| 107 |
v|m|c |
| 108 |
v2|Jan|bar |
| 109 |
v1|Apr|foo |
| 110 |
v1|Jul|baz |
| 111 |
v0|Jul|qux |
| 112 |
-- |
| 113 |
v|Jan|Apr|Jul |
| 114 |
v2|bar|| |
| 115 |
v1||foo|baz |
| 116 |
v0|||qux |
| 117 |
|
| 118 |
select v,to_char(d,'Mon') as m, c, extract(month from d) as mnum from v_data order by v \crosstabview v m c mnum |
| 119 |
-- |
| 120 |
v|m|c|mnum |
| 121 |
v0|Jul|qux|7 |
| 122 |
v1|Apr|foo|4 |
| 123 |
v1|Jul|baz|7 |
| 124 |
v2|Jan|bar|1 |
| 125 |
-- |
| 126 |
v|Jan|Apr|Jul |
| 127 |
v0|||qux |
| 128 |
v1||foo|baz |
| 129 |
v2|bar|| |
| 130 |
|
| 131 |
select v,to_char(d,'Mon') as m, c, -1*extract(month from d) as revnum from v_data order by v \crosstabview v m c revnum |
| 132 |
-- |
| 133 |
v|m|c|revnum |
| 134 |
v0|Jul|qux|-7 |
| 135 |
v1|Apr|foo|-4 |
| 136 |
v1|Jul|baz|-7 |
| 137 |
v2|Jan|bar|-1 |
| 138 |
-- |
| 139 |
v|Jul|Apr|Jan |
| 140 |
v0|qux|| |
| 141 |
v1|baz|foo| |
| 142 |
v2|||bar |
| 143 |
|
| 144 |
SELECT first, second, first > 2 AS gt2 FROM my_table \crosstabview first second |
| 145 |
-- |
| 146 |
first|second|gt2 |
| 147 |
1|one|f |
| 148 |
2|two|f |
| 149 |
3|three|t |
| 150 |
4|four|t |
| 151 |
-- |
| 152 |
first|one|two|three|four |
| 153 |
1|f||| |
| 154 |
2||f|| |
| 155 |
3|||t| |
| 156 |
4||||t |
| 157 |
|
| 158 |
SELECT t1.first as A, t2.first+100 AS B, t1.first*(t2.first+100) as AxB, row_number() over(order by t2.first) AS ord FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC \crosstabview A B AxB ord |
| 159 |
-- |
| 160 |
a|b|axb|ord |
| 161 |
4|103|412|11 |
| 162 |
4|104|416|13 |
| 163 |
4|102|408|7 |
| 164 |
4|101|404|4 |
| 165 |
3|104|312|16 |
| 166 |
3|101|303|3 |
| 167 |
3|102|306|6 |
| 168 |
3|103|309|9 |
| 169 |
2|101|202|2 |
| 170 |
2|104|208|14 |
| 171 |
2|102|204|5 |
| 172 |
2|103|206|10 |
| 173 |
1|102|102|8 |
| 174 |
1|103|103|12 |
| 175 |
1|104|104|15 |
| 176 |
1|101|101|1 |
| 177 |
-- |
| 178 |
a|101|102|103|104 |
| 179 |
4|404|408|412|416 |
| 180 |
3|303|306|309|312 |
| 181 |
2|202|204|206|208 |
| 182 |
1|101|102|103|104 |