- - PR -
SQLで年月のダミー表を作りたい
1
| 投稿者 | 投稿内容 |
|---|---|
|
投稿日時: 2005-02-14 13:59
テーブルA
2004/02 チョコ 10個 2004/10 チョコ 25個 テーブルB 2004/03 ケーキ 22個 2004/04 ケーキ 24個 という表があるときに A B ------------- 2004/01 2004/02 10 2004/03 22 2004/04 24 2004/05 2004/06 2004/07 2004/08 2004/09 2004/10 25 2004/11 2004/12 ------------- という結果を返したい場合のSQLが考えつきません。 2004/01〜12までの月のダミー表が作れればなんとかなるのですが・・。 どなたかご教授いただけないでしょうか。 よろしくお願い致します。 |
|
投稿日時: 2005-02-14 14:01
すみません、スペースは詰められるんですね。
訂正します。 A B ------------- 2004/01 2004/02 10 2004/03 22 2004/04 24 2004/05 2004/06 2004/07 2004/08 2004/09 2004/10 25 2004/11 2004/12 ------------- |
|
投稿日時: 2005-02-14 14:13
どもでふ。がると申します。
…んっと。ものすごく単純な質問で恐縮なのですが。 「プログラムで片付ける」ではなにかまずいんでしょうか? いあ、ちょっと興味があったもので。 |
|
投稿日時: 2005-02-14 15:33
こんにちは。
質問の意図に則しているかわかりませんが、 SQLのみとなるとこんなのはだめなのですか? select dmytbl.yyyymm from ( select '2004/01' as yyyymm from dual union all select '2004/02' as yyyymm from dual union all select '2004/03' as yyyymm from dual union all select '2004/04' as yyyymm from dual union all select '2004/05' as yyyymm from dual union all select '2004/06' as yyyymm from dual union all select '2004/07' as yyyymm from dual union all select '2004/08' as yyyymm from dual union all select '2004/09' as yyyymm from dual union all select '2004/10' as yyyymm from dual union all select '2004/11' as yyyymm from dual union all select '2004/12' as yyyymm from dual ) dmytbl; |
|
投稿日時: 2005-02-14 16:13
>ピゴナダさん
dualテーブルとwhere句でなんとかならないものか試行錯誤してましたが、 このSQLでばっちり解決です。 ご回答ありがとうございました。 >がるがるさん 単発の問い合わせなので、SQLでなんとかならないかと考えました。 |
|
投稿日時: 2005-02-14 18:32
>このSQLでばっちり解決です。
補足ですが、yyyyの部分はこんな風にする必要はありませんか? select to_char( sysdate, 'yyyy' ) || '/01' from dual union all :(略) select to_char( sysdate, 'yyyy' ) || '/12' from dual |
1
