按日期排序desc,但在日期顺序asc(Order by date desc, but within day order by time asc)

编程入门 行业动态 更新时间:2024-10-27 08:29:25
按日期排序desc,但在日期顺序asc(Order by date desc, but within day order by time asc)

我有一个表,其中有一个Date (smalldatetime)列。 我需要order by Date DESC ,但是每天都要order by Date ASC 。 输出应该像:

Date 2017-01-31T09:00:00Z 2017-01-31T17:00:00Z 2017-01-28T09:00:00Z 2017-01-28T17:00:00Z 2017-01-25T09:00:00Z 2017-01-25T17:00:00Z ...

这样的查询可能吗?

如果有任何帮助,则数据最多包含同一Date的两行。

I have a table in which there is a Date (smalldatetime) column. I need to order by Date DESC, but within each day to order by Date ASC. The output should be like:

Date 2017-01-31T09:00:00Z 2017-01-31T17:00:00Z 2017-01-28T09:00:00Z 2017-01-28T17:00:00Z 2017-01-25T09:00:00Z 2017-01-25T17:00:00Z ...

Is such a query possible?

If it's of any help, the data contains a maximum of two rows for the same Date.

最满意答案

铸就date

ORDER BY CAST([Date] AS date) DESC ,CAST([Date] AS time) ASC

Cast to dateand then to time

ORDER BY CAST([Date] AS date) DESC ,CAST([Date] AS time) ASC

更多推荐

本文发布于:2023-07-07 15:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1065198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但在   顺序   日期   按日   desc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!