我有一个日期格式为“12/14/2017”的表,我想创建另一个列,将月份与此日期字符串分开,并将其命名为“January”而不是“01”。我想我需要CASE函数和某种DATE函数的混合。
表:
Column A
12/14/2017
12/11/2017
2/16/2018
1/2/2017
我需要的输出我将列B:
Column A Column B (Output)
12/14/2017 December
12/11/2017 December
2/16/2018 February
1/2/2017 January
答案 0 :(得分:1)
您可以将值转换为日期,然后转换为月份字符串:
DATE_FORMAT(TO_DATE(columnA, 'MM/DD/YYYY', 'MMMM')
答案 1 :(得分:0)
SELECT columnA,
CASE EXTRACT(MONTH FROM TO_DATE(columnA,'mm/dd/yyyy'))
WHEN 1 THEN 'January'
WHEN 2 THEN 'February'
WHEN 3 THEN 'March'
WHEN 4 THEN 'April'
WHEN 5 THEN 'May'
WHEN 6 THEN 'June'
WHEN 7 THEN 'July'
WHEN 8 THEN 'August'
WHEN 9 THEN 'September'
WHEN 10 THEN 'October'
WHEN 11 THEN 'November'
WHEN 12 THEN 'December'
END AS columnB
FROM yourTable