Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- `client_id` as `clientId`,
- ( SELECT COUNT(*) FROM `clients` WHERE `client_id` = clientId AND `date` >= '2020-01-01 00:00:00' AND `date` <= '2020-02-01 00:00:00' ) AS `second_month`,
- ( SELECT COUNT(*) FROM `clients` WHERE `client_id` = clientId AND `date` >= '2019-12-01 00:00:00' AND `date` <= '2020-01-01 00:00:00' ) AS `third_month`
- FROM
- `clients`
- WHERE
- `date` >= '2020-02-01 00:00:00'
- AND `date` <= '2020-03-01 00:00:00' HAVING `second_month` > 0 AND `third_month` > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement