我得到了我的sql查询工作,但是当我找到具有相同小时和分钟的日期时,我无法使查询工作。例如: Max(日期时间)忽略秒
在列“trans_date”我无法使用我的查询,因为与max(trans_date)我没有得到任何结果,不知何故SQL是忽略秒。
这是我的完整的SQL语句:
SELECT till.code,art.description
FROM [TCPOS4].[dbo].[transactions] as tra,
TCPOS4.dbo.articles as art,[TCPOS4].[dbo].[trans_articles] as tro,
[TCPOS4].[dbo].[tills] as till,[TCPOS4].[dbo].[shops] as shop
where tra.till_id=till.id and shop.id=till.shop_id and tro.transaction_id=tra.id and
art.id=tro.article_id and tra.trans_date =(select max(trans_date)
from tcpos4.dbo.transactions as t2 where t2.till_id=tra.till_id and trans_date > '2016-10-26 00:00:0.000' and trans_date< '2016-10-27 00:00:00.000')
group by till.code,art.description
与此查询我正在从2016年10月26日至2016年10月27日的最高TRANSACTION_DATE每个“代码”,但我不从代码“5446”获取任何信息。我应该得到“TABLE CHOCOLECHE-CONGUITOS”,因为它是范围内的最大trans_date。
是该范围内的TRANS_DATE '2016年10月26日00:00:0.000' 到 '2016年10月27日00:00:00.000' 独家?你没有得到什么日期? – Cato
我想这个问题是在'INNER JOIN'周围的某个地方。倾向于使用显式连接语法,而不是“通过逗号和谓词在哪里”来连接oldschool。 –
该行的日期是图片中的第一张,与其他日期几乎相同。我认为问题出在那里,因为我一直在做实验,并且出现错误,我有相同的时间和分钟。那么,我没有错误,查询只是忽略了代码'5446' – talendguy