我的问题是显示工作日而不是日期。在片刻,这是有效的:
SELECT
Sum(PostQuantity) AS Amount,
to_char(PostingDate, 'dd-mm-yyyy') AS Day
FROM
table1
GROUP BY to_char(PostingDate, 'dd-mm-yyyy')
ORDER BY to_char(PostingDate, 'dd-mm-yyyy')
但这会显示日期。添加以下功能:
SELECT
Sum(PostQuantity) AS Amount,
DatePart(Weekday,PostingDate) AS Day
或
SELECT
Sum(PostQuantity) AS Amount,
DateName(dw,PostingDate) AS Day
不起作用。我认为我的问题是使用了PostingDate
运算符中的SELECT
,但我尝试修复它并不起作用。
答案 0 :(得分:1)
我没有在您的代码中看到问题,但有时会尝试替代方案。试试这个:
SELECT SUM(t.postQuantity) as amount,
TO_CHAR(t.PostingDate,'DAY') as dayOfTheWeek
FROM YourTable t
GROUP BY TO_CHAR(t.PostingDate,'DAY')
Dy
会给你前三个字母。
答案 1 :(得分:0)
如果它在sql
上,你可以使用DATENAME功能SELECT DATENAME(WEEKDAY,[Date])
FROM Table1
在Oracle中
select to_char(to_date('03/09/1982','dd/mm/yyyy'), 'DY')