select
loginname as 'Officer',
CONVERT(VARCHAR(10), visit.tmstamp, 105) as 'Date',
visit.queueno
from visit,event where ( visit.branchno='1007' )
and
(visit.wstation='1' or visit.wstation='10' or visit.wstation='11' or visit.wstation='15' or visit.wstation='2' or visit.wstation='20' or visit.wstation='21' or visit.wstation='23' or visit.wstation='24' or visit.wstation='28' or visit.wstation='29' or visit.wstation='3' or visit.wstation='30' or visit.wstation='31' or visit.wstation='32' or visit.wstation='33' or visit.wstation='4' or visit.wstation='5' or visit.wstation='6' or visit.wstation='7' or visit.wstation='8' or visit.wstation='9' ) and (visit.catname='BY PASS' or visit.catname='REG STORE' or visit.catname='REGISTRATION' or visit.catname='ROOM 1 to 4' or visit.catname='ROOM A1 & A2' or visit.catname='ROOM A3 & A4' or visit.catname='ROOM A5-A7&A9-A11' or visit.catname='ROOM A8-BMD' or visit.catname='ROOM B20' or visit.catname='ROOM B21 B23 B24' or visit.catname='Ward Cases' ) and (visit.btnname='BY PASS' or visit.btnname='REG STORE' or visit.btnname='REGISTRATION' or visit.btnname='ROOM 1 to 4' or visit.btnname='ROOM A1 & A2' or visit.btnname='ROOM A3 & A4' or visit.btnname='ROOM A5-A7&A9-A11' or visit.btnname='ROOM A8-BMD' or visit.btnname='ROOM B20' or visit.btnname='ROOM B21' or visit.btnname='B23' or visit.btnname='B24' or visit.btnname='Ward Cases' ) and ( (Day(visit.tmstamp)=1 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=2 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=3 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=4 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=5 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=6 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=7 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=8 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=9 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=10 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=11 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=12 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=13 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=14 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=15 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=16 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=17 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=18 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=19 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=20 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=21 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=22 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=23 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=24 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=25 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=26 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=27 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=28 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=29 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=30 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) OR (DAY(visit.tmstamp)=31 AND MONTH(visit.tmstamp)=12 AND YEAR(visit.tmstamp)=2010) )
and
((loginname='Administrator') or (loginname='121 JUDY YAP CHEO T') or (loginname='044 Noor Faiza') or (loginname='109 Jaya'))
and
(CONVERT(VARCHAR(10), visit.tmstamp, 105)=CONVERT(VARCHAR(10), event.tmstamp, 105))
and
(visit.loginid=event.loginid)
当我查询上面的代码时,我得到了两次结果。
如果管理员有一行用queueno 1005, 我得了两次。
有什么想法吗?
答案 0 :(得分:2)
如果queueno 1005只有一个访问行,则必须有2个事件行,其中loginid与访问行的loginid匹配。
答案 1 :(得分:1)
如何缩短它?
and visit.wstation in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 20, 21, 23, 24, 28, 29, 30, 31, 32, 33)
and visit.tmstamp between '20110101' and '20101201'
其他标准可以做类似的事情。
避免像这样的讽刺的一个好方法是不允许编写糟糕的工具来生成SQL。