[英]SELECT DATEPART, DATENAME or other? SQL
我正在創建一個新查詢,我想在其中添加三個附加列(相同格式):
周數(截至08)/月(截至2月)/年(截至2019)
SELECT hd.F91 AS [PO Number],
hd.F1032 AS [Trs Number],
hd.F76 AS [Order Date],
hd.F27 AS [Vendor ID],
hd.F334 AS [Vendor Name],
hd.F1127 AS Admin,
hd.F1068 AS State,
hd.F1067 AS Status,
tl.F65 AS Total,
DATEPART(wk,[Order Date]) AS [Week Number],
DATENAME('month',[Order Date]) AS Month,
DATENAME('year',[Order Date]) AS Year,
其余數據正在從我們的系統中提取,但是我嘗試根據稱為Order Date(日期格式)的現有列獲取這三列。
不幸的是,下面的錯誤出現了。 歡迎所有嘗試的建議。 謝謝!
這些功能可以在mysql中使用(在編輯之前是問題的標簽!!!):
WEEK([Order Date], 1) AS [Week Number],
MONTHNAME([Order Date]) AS Month,
YEAR([Order Date]) AS Year,
根據需要更改WEEK
的參數1
( https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week )
試試這個在postgreSQL to_char([order date],'Month')中對我有用
這個問題最初是為POSTGRES標簽的。
ANSI標准功能是:
extract(week from "Order Date")
extract(month from "Order Date")
extract(year from "Order Date")
Postgres支持此標准語法。
如果需要字符串,可以使用to_char()
:
to_char("Order Date", 'WW')
to_char("Order Date", 'YYYY')
to_char("Order Date", 'Month')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.