SQL
- 3 ответа
- 0 вопросов
1
Вклад в тег
SELECT DATE_FORMAT(`date`, '%Y-%m-%d') AS my_date, count(id) FROM posts GROUP BY my_date ORDER BY `date` DESC LIMIT 7
select DATE_FORMAT(`date`, '%Y-%m-%d') AS my_date, count(id) FROM posts WHERE my_date IN (
DATE_FORMAT(NOW(), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 1 * 24 * 60 * 60), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 2 * 24 * 60 * 60), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 3 * 24 * 60 * 60), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 4 * 24 * 60 * 60), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 5 * 24 * 60 * 60), '%Y-%m-%d'),
DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - 6 * 24 * 60 * 60), '%Y-%m-%d')
) GROUP BY my_date
SELECT c.id, c.name FROM orders AS o INNER JOIN clients c ON o.id_client=c.id GROUP BY o.id_client HAVING count(o.id_client) > 3