Last active
December 11, 2015 11:28
-
-
Save thomaspuppe/4593700 to your computer and use it in GitHub Desktop.
Extract Month and Year from a datetime/timestamp coloumn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### With timestamp/integer coloumn (1354711936) | |
SELECT | |
FROM_UNIXTIME(crdate, '%Y') AS year, | |
FROM_UNIXTIME(crdate, '%M') AS month, | |
COUNT(uid) AS number | |
FROM `tx_campeforms_domain_model_contact` | |
WHERE interest LIKE "%Techniker%" | |
AND email NOT LIKE "%test.de%" | |
AND email NOT LIKE "%ondigo.de%" | |
GROUP BY year, month | |
ORDER BY year, month | |
### with datetime coloumn (2012-12-05 13:52:16) | |
SELECT | |
extract(month from tweet.creation) AS month, | |
extract(year from tweet.creation) AS year, | |
count(tweet.id) AS count | |
FROM tweet tweet | |
WHERE tweet.screenname = ? | |
AND tweet.creation >= ? | |
GROUP BY year, month | |
ORDER BY year, month |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment