Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. SELECT
  2. `client_id` as `clientId`,
  3. ( 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`,
  4. ( 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`
  5. FROM
  6. `clients`
  7. WHERE
  8. `date` >= '2020-02-01 00:00:00'
  9. 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