所以我有一个重复问题与我的一个报告。 我目前通过运行的Microsoft SQL Server 2012 此查询就是我一起工作:重复问题与查询
SELECT
oh.ORDERNO,
od.Rxnum,
oh.STATUS,
datediff(hh, o.recvtime, getdate()) as ageInHours
FROM
mck_hvs.ORDERHEADER oh with (nolock),
mck_hvs.ORDERDETAILS od with (nolock),
mck_hvs.SCRIPTITEMS si with (nolock),
mck_hvs.orderheader o with(nolock)
WHERE
oh.orderno = od.orderno and
si.orderno = od.orderno and
oh.STATUS = 550 and
od.DrugClass = 'C2' and
datediff(hh, o.recvtime, getdate()) <24
ORDER BY
oh.STATUS,
oh.orderno,
od.rxnum,
datediff(hh, o.recvtime, getdate()) desc
我想获得一份报告,列出了具体的订单号码,我的药店,它会列出它们关闭,但可以有20-30页的相同订单号码信息。
我猜你的连接会导致比你想要的更多的行。也许一次添加一个表并使用现代连接语法。 – Degan