【发布时间】:2014-11-28 21:11:38
【问题描述】:
我在 SQL 中遇到了这种情况,我需要显示 dr_DRVNUM、DR_DRVNAME 和多天工作同一班次的司机的工作天数。
我在 SQL 中有这段代码,到目前为止我也尝试了不同的代码,但仍然没有任何运气
select dr_drvname, dr_drvnum, sh_wkdate
case when sh_drvnum = dr_drvnum and sh_wkshift = 'DAY' then count(sh_wkdate)
end
from driver, shift
我有一张桌子我正在上传下面这张桌子图片的一部分,
DR_DRVNUM DR_DRVNAME SH_WKDATE SH_WKSHIFT
0001 Cooper, Randolph B. 15-NOV-07 DAY
0001 Cooper, Randolph B. 15-NOV-07 DAY
0001 Cooper, Randolph B. 15-NOV-07 DAY
0001 Cooper, Randolph B. 15-NOV-07 EVE
0001 Cooper, Randolph B. 15-NOV-07 EVE
0001 Cooper, Randolph B. 15-NOV-07 EVE
0001 Cooper, Randolph B. 15-NOV-07 NIG
0001 Cooper, Randolph B. 15-NOV-07 NIG
0001 Cooper, Randolph B. 15-NOV-07 NIG
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 DAY
0001 Cooper, Randolph B. 16-NOV-07 EVE
0001 Cooper, Randolph B. 16-NOV-07 EVE
【问题讨论】:
-
mysql 还是 sql-server?
-
Cooper 是否有几个日班,例如07 年 11 月 15 日还是应该算作一个班次?如果有,为什么要重复行?
-
谢谢你们,我想通了。顺便说一句,我想做的是,如果库珀在安全轮班前“DAY,OR EVE OR NIG”工作超过一天,那么如果他在 11 月 15 日 Day/NIG/EVE 轮班工作,那么它的计算天数只有那么 fucntion不算数
标签: mysql sql sql-server-2008