开发者

Sql by hour starting at noon

开发者 https://www.devze.com 2022-12-22 10:10 出处:网络
I\'m currently using a select statement with one column as DATEPART(hh, CallTime) AS H开发者_开发技巧our

I'm currently using a select statement with one column as DATEPART(hh, CallTime) AS H开发者_开发技巧our and then doing:

GROUP BY DATEPART(hh, CallTime) 
ORDER BY Hour

This displays the hours starting at midnight and going through midnight - how would I go about having this go from noon to noon? Thanks!


CASE WHEN (DATEPART(hh, CallTime) >=12) THEN DATEPART(hh, CallTime) - 12 ELSE DATEPART(hh, CallTime)+12 END AS hour_since_noon should do it if I understood your question correctly.

You may want to have 2 separate fields, your original one to actually display and this one to order

0

精彩评论

暂无评论...
验证码 换一张
取 消