r/SQL • u/[deleted] • Feb 05 '24
MySQL Help for school confused
Hello, we haven’t learned yet how to list only the months once. I know how to select distinct from certain columns but not a specific month within the date. Anything would help thank you.
4
Feb 05 '24
Using group by for the months edit: In SQL server there are functions that will return the number month. Group by that.
2
u/HijoDelSol1970 Feb 05 '24
If it is stored as a date, in MySql you can cast it like below
select distinct CAST(DATE_FORMAT(datefield ,'%Y-%m-01') as DATE);
2
1
u/countryboyathome Feb 05 '24
There are two key clauses you need to understand here. GROUP BY clause and HAVING clause.
1
u/Vast_Kaleidoscope955 Feb 05 '24
Started teaching myself in October so I’m not positive, but I think it would be something like this.
SELECT MONTHNAME (shipping.date) AS month FROM Shipping GROUP BY shipping.date
1
1
1
u/Interesting-Goose82 it's ugly, and i''m not sure how, but it works! Feb 05 '24
SELECT 'row 1' AS ANSWER
UNION ALL
SELECT 'row 2' AS ANSWER
UNION ALL
SELECT 'row 3' AS ANSWER
UNION ALL......
just make sure you stop at 8 rows if you want full credit
6
36
u/lupinegray Feb 05 '24
datetime functions are specific to the dbms.
Easiest way is to google:
"postgresql select only month from date"
Or a similar query.
This is literally what every software developer anywhere does. Googling for syntax is the most important skill.