Skip to content
mitochondrion edited this page May 5, 2017 · 12 revisions

Examples

Most X of the Day

SELECT X, count(X) FROM some_table WHERE some_condition AND date_column between '2016-04-01 00:00:00' and '2016-04-01 23:59:00' GROUP BY X ORDER BY COUNT(X) DESC

Top X of the day (Historical)

SELECT date, X, MAX(count)
FROM (SELECT DATE(date_column) as date, X, COUNT(X) as count
      FROM some_table
      WHERE some_condition
      GROUP BY DATE(date_column), symbol
      ORDER BY DATE(date_column) DESC, COUNT(X) DESC) as whatever
GROUP BY date
ORDER BY date DESC, count DESC

Find containing

SELECT * FROM some_table WHERE some_column LIKE "%string to look for%"

Rows per date

SELECT DISTINCT(DATE(date_column)), count(date_column) FROM some_table GROUP BY DATE(date_column)

Clone this wiki locally