首页 > 数据库 > 数据库开发技术 > 使用SQL实现特殊查询(1)
对于一个表如下:
SQL> select * from t; A B ----------- --------------------------------------- 2006-2-1 1 2006-2-2 1 2006-2-3 1 2006-2-4 1 2006-2-5 1 2006-2-6 1 2006-2-7 1 2006-2-8 1 2006-2-9 1 2006-2-10 1 10 rows selected SQL> desc t; Name Type Nullable Default Comments ---- ------- -------- ------- -------- A DATE Y B INTEGER Y SQL> |
如何能够实现查询能够实现如下的查询:
DT NVL(B.B,0) ----------- ---------- 2006-2-1 1 2006-2-2 1 2006-2-3 1 2006-2-4 1 2006-2-5 1 2006-2-6 1 2006-2-7 1 2006-2-8 1 2006-2-9 1 2006-2-10 1 2006-2-17 0 2006-2-18 0 2006-2-24 0 2006-2-13 0 2006-2-11 0 2006-2-12 0 2006-2-20 0 2006-2-22 0 2006-2-21 0 2006-2-16 0 DT NVL(B.B,0) ----------- ---------- 2006-2-28 0 2006-2-23 0 2006-2-26 0 2006-2-25 0 2006-2-14 0 2006-2-27 0 2006-2-15 0 2006-2-19 0 28 rows selected |
具体的查询如下:
select a.dt, nvl( b.b, 0 ) from ( select to_date( '2006-02-01','yyyy-mm-dd' ) + rownum -1 dt from all_objects where rownum <= last_day( to_date('2006-02-27','yyyy-mm-dd') ) - to_date( '2006-02-01','yyyy-mm-dd' ) + 1 ) A, t B where a.dt = b.a (+) / |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/222350/viewspace-909452/ ,如需转载,请注明出处,否则将追究法律责任。