私のクエリが返されます:
+------+------+------+------+------+------+------+-------+------+------+------+------+-----+
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Bla |
+------+------+------+------+------+------+------+-------+------+------+------+------+-----+
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 13 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 14 |
| 0 | 0 | 0 | 0 | 0 | 9 | 0 | 0 | 0 | 0 | 8 | 37 | 29 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 374 | 30 |
| 0 | 0 | 1 | 0 | 78 | 2 | 4 | 8 | 57 | 169 | 116 | 602 | 31 |
| 156 | 255 | 79 | 75 | 684 | 325 | 289 | 194 | 407 | 171 | 584 | 443 | 32 |
| 1561 | 2852 | 2056 | 796 | 2004 | 1755 | 879 | 1052 | 1490 | 1683 | 2532 | 2381 | 33 |
| 4167 | 3841 | 4798 | 3399 | 4132 | 5849 | 3157 | 4381 | 4424 | 4487 | 4178 | 5343 | 34 |
| 5472 | 5939 | 5768 | 4150 | 7483 | 6836 | 6346 | 6288 | 6850 | 7155 | 5706 | 5231 | 35 |
| 5749 | 4741 | 5264 | 4045 | 6544 | 7405 | 7524 | 6625 | 6344 | 5508 | 6513 | 3854 | 36 |
| 5464 | 6323 | 7074 | 4861 | 7244 | 6768 | 6632 | 7389 | 8077 | 8745 | 6738 | 5039 | 37 |
| 5731 | 7205 | 7476 | 5734 | 9103 | 9244 | 7339 | 8970 | 9726 | 9089 | 6328 | 5512 | 38 |
| 7262 | 6149 | 8231 | 6654 | 9886 | 9834 | 9306 | 10065 | 9983 | 9984 | 6738 | 5806 | 39 |
| 5886 | 6934 | 7137 | 6978 | 9034 | 9155 | 7389 | 9437 | 9711 | 8665 | 6593 | 5337 | 40 |
+------+------+------+------+------+------+------+-------+------+------+------+------+-----+
ご覧のとおり、BLA 列は 13 から始まります。1、2、3 などのように開始したいのですが、データにギャップがないようにしたいのです。ギャップがある理由は、すべての月が0
その特定のためのものだからですbla
のすべての値を含む結果セットを取得するにはどうすればよいBLA
です0
か?
望ましい結果は次のとおりです。
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Bla |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 12 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 13 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 14 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 15 |
| … | … | … | … | … | … | … | … | … | … | … | … | … |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
ここに私のクエリがあります:
SELECT CASE WHEN SUM(Jan) is not null THEN SUM(Jan) ELSE 0 end Jan,
CASE WHEN SUM(Feb) is not null THEN SUM(Feb) ELSE 0 end Feb,
CASE WHEN SUM(Mar) is not null THEN SUM(Mar) ELSE 0 end Mar,
CASE WHEN SUM(Apr) is not null THEN SUM(Apr) ELSE 0 end Apr,
CASE WHEN SUM(May) is not null THEN SUM(May) ELSE 0 end May,
CASE WHEN SUM(Jun) is not null THEN SUM(Jun) ELSE 0 end Jun,
CASE WHEN SUM(Jul) is not null THEN SUM(Jul) ELSE 0 end Jul,
CASE WHEN SUM(Aug) is not null THEN SUM(Aug) ELSE 0 end Aug,
CASE WHEN SUM(Sep) is not null THEN SUM(Sep) ELSE 0 end Sep,
CASE WHEN SUM(Oct) is not null THEN SUM(Oct) ELSE 0 end Oct,
CASE WHEN SUM(Nov) is not null THEN SUM(Nov) ELSE 0 end Nov,
CASE WHEN SUM(Dec) is not null THEN SUM(Dec) ELSE 0 end Dec,
CASE WHEN Bla > 191 THEN 192 ELSE Bla END Bla
FROM CTE
GROUP BY CASE WHEN Bla > 191 THEN 192 ELSE Bla END
order by bla