表的结构是:
date shift
2011-01-20 甲班
2011-01-20 乙班
2011-01-20 丙班
2011-01-20 丁班
2011-01-21 甲班
2011-01-21 乙班
我想查询出某天却少哪个班,
比如我查询2011-01-21 的shift 应该是缺少 丙班和丁班
应该怎么查询
date shift
2011-01-20 甲班
2011-01-20 乙班
2011-01-20 丙班
2011-01-20 丁班
2011-01-21 甲班
2011-01-21 乙班
我想查询出某天却少哪个班,
比如我查询2011-01-21 的shift 应该是缺少 丙班和丁班
应该怎么查询
解决方案 »
- 如何用rownumber对表进行分页查询?
- 非常疑惑~~实在搞不懂这是为什么
- 如何替换字段内的"?"符号呢
- 使用视图是否会比查询表速度慢呢
- 存储过程种update一批数据,对于处于锁状态的数据需要特殊处理。如何在程序中查出被锁的记录?
- 请问ASP中连接Oracle数据库,其连接字符串怎么写?
- oracle的视图能否实现像sql server的视图一样的左联接或右联接或full
- 哪有下载Oracle8i的帮助文档?html格式的
- 我在线!在P4 XP上装ORACLE8.16NT企业版,装不上点了SETUP没有反应听说要改一个文件名字或者是下一个补丁,是什么 啊谢谢了
- BIEE出现为此页应用仪表盘定制时出错。 单击">此处以了解详细信息。
- 诚心请教 Oracle 9I 向 Oracle 10G 迁移
- 求助!!!局域网其他机器无法访问我本机安装的oracle服务
with A as(
select '甲' shift from dual union all
select '乙' shift from dual union all
select '丙' shift from dual union all
select '丁' shift from dual
),
B as(
select '2011-01-20' dates from dual union all
select '2011-01-21' dates from dual
),
C as(
select '2011-01-20' dates,'甲' shift from dual union all
select '2011-01-20' dates,'乙' shift from dual union all
select '2011-01-20' dates,'丙' shift from dual union all
select '2011-01-20' dates,'丁' shift from dual union all
select '2011-01-21' dates,'甲' shift from dual union all
select '2011-01-21' dates,'乙' shift from dual
)select B.dates,A.shift
from A,B
minus
select C.dates,C.shift
from C
再按照日期条件 重构建下B表就好了
这是传说中的CTE(common table expression),和minus的使用吧!
shift
甲
乙
丙
丁然后
select * from 表B where shift not in(select shift from 表A where date=你需要查的日期)
看是不是四条时用 select count(shift) from table_name group by date; 把不是四样的date记录下来,再以这个date为条件查具体是少哪个。
新手,不知道对不对
但是有现成的minus 为啥不利用呢
select * from 表B where shift not in(select shift from 表A where date=你需要查的日期 group by shift)
即可