我有这样的查询,
SELECT
CONVERT(VARCHAR(3), DATENAME(MONTH, date)) + '-' +
RIGHT(DATENAME(YEAR, date), 2) AS date
FROM
tblSample
GROUP BY
CONVERT(VARCHAR(3), DATENAME(MONTH, date)) + '-' +
RIGHT(DATENAME(YEAR, date), 2) AS date
ORDER BY
CONVERT(VARCHAR(3), DATENAME(MONTH, date)) + '-' +
RIGHT(DATENAME(YEAR, date), 2) AS date
我有这样的数据:
Apr-17
jan-16
jan-17
mar-17
我要求输出应按年份排序,这意味着应显示所有“17”(年份)数据。就像我们必须按年份使用订单只能如何做到这一点?
答案 0 :(得分:2)
您必须按照下面的查询更改订单,按顺序包括月份名称和年份,而不是按顺序选择年份
ORDER BY RIGHT(DATENAME(YEAR, date), 2) AS date
如果您想在第一年和当月申请订单,请按以下方式编写查询:
ORDER BY RIGHT(DATENAME(YEAR, [date]), 2) DESC, CONVERT(VARCHAR(3), DATENAME(MONTH, [date]))
我试过以下数据:
DECLARE @tblA AS TABLE(
[date] date
)
INSERT INTO @tblA VALUES('01-Apr-2017')
INSERT INTO @tblA VALUES('01-Jan-2016')
INSERT INTO @tblA VALUES('01-Jan-2017')
INSERT INTO @tblA VALUES('01-Mar-2017')
SELECT
CONVERT(VARCHAR(3), DATENAME(MONTH, [date])) + '-' +
RIGHT(DATENAME(YEAR, [date]), 2) AS date
FROM @tblA ORDER BY YEAR([date]) DESC, MONTH([date])
<强>输出:强>
答案 1 :(得分:2)
select CONVERT(VARCHAR(3),DATENAME(MONTH,date))+'-
'+right(DATENAME(YEAR,date),2) as date from
tblSample
order by YEAR([date]),MONTH([date])
答案 2 :(得分:0)
project.findProperty('buildNumber')