sql server 分组查询结合日期模糊查询

时间:2022-09-16 13:04:57

分组查询:

https://www.cnblogs.com/netserver/p/4518995.html

日期格式化格式:

http://blog.csdn.net/qq_16769857/article/details/52289627

日期和字符串之间的转换:

https://www.cnblogs.com/windphoenix/archive/2013/04/26/3044784.html

日期的模糊查询:

https://zhidao.baidu.com/question/507141127.html

 

SELECT a.*
FROM WATERQuarter a INNER JOIN
(SELECT datacd, MAX(tm) tm
FROM waterQuarter
GROUP BY datacd) b ON a.DATACD = b.datacd AND a.TM = b.tm 
AND  CONVERT(varchar, a.TM, 23) LIKE '2017-11-24%'

ORDER BY a.TM DESC

 

SELECT a.*
FROM WATERQuarter a INNER JOIN
(SELECT datacd, MAX(tm) tm
FROM waterQuarter
GROUP BY datacd) b ON a.DATACD = b.datacd AND a.TM = b.tm 
WHERE  CONVERT(varchar, a.TM, 23) LIKE '2017-11-24%'
ORDER BY a.TM DESC

 

SELECT a.*
FROM WATERQuarter a INNER JOIN
(SELECT datacd, MAX(tm) tm
FROM waterQuarter
GROUP BY datacd) b ON a.DATACD = b.datacd AND a.TM = b.tm AND 
CONVERT(varchar, a.TM, 23) LIKE CONVERT(varchar, GETDATE(), 23)
ORDER BY a.TM DESC