0

嘿,我似乎无法解决这个问题,我有这个查询:

SELECT  DISTINCT CONVERT(VARCHAR(8), time, 4) AS Batch  
FROM Calls 
ORDER BY Batch

它按天而不是常规日期对列进行排序,这意味着我得到了类似的东西:

1.11.12
1.12.12
2.11.12
3.11.12
4.11.12

我怎么能解决这个问题?如果我尝试按时间排序,则查询不会区分值并弄乱我的所有查询。

这意味着:

SELECT  DISTINCT CONVERT(VARCHAR(8), time, 4) AS Batch , time 
FROM Calls 
ORDER BY time, Batch

对查询进行很好的排序,但不会区分这些值。

4

1 回答 1

1

试试这个

SELECT  DISTINCT CONVERT(VARCHAR(8), time, 4) AS Batch
FROM Calls 
ORDER BY time, Batch

更新:

select convert(varchar(8), time, 4) as [Batch]
from [Calls]
group by convert(varchar(8), time, 4)
order by convert(datetime, convert(varchar(8), time, 4), 4)

SQL 提琴示例

于 2012-12-02T08:02:45.103 回答