Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

sql - datepart year AND quarter in one column in MySQL

I need to parse out the year and quarter from the Date column. My data looks like this:

Feb 1, 2019
Feb 2, 2019

Desired output is:

2019, 1
2019, 1

I have tried:

QUARTER(`Date`)

But this only gives me back the quarter 1. Can't find a way to include both year and the quarter. Thank you!

question from:https://stackoverflow.com/questions/65904382/datepart-year-and-quarter-in-one-column-in-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use CONCAT to show both year and quarter

SELECT CONCAT(YEAR("2017-06-15"), ", ", QUARTER("2017-06-15"));   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...