Skip to content

Instantly share code, notes, and snippets.

@chanakaDe
Created October 13, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanakaDe/0a4d0e89e0f13dd818e0d3aa8437158b to your computer and use it in GitHub Desktop.
Save chanakaDe/0a4d0e89e0f13dd818e0d3aa8437158b to your computer and use it in GitHub Desktop.
#not_null_order_count
select count(*) not_null_order_count, DATE_FORMAT(orders.created_at, "%Y-%m-%d") as order_date from `orders` inner join `order_items` on `order_items`.`order_id` = `orders`.`id` where exists (select * from `order_items` where `orders`.`id` = `order_items`.`order_id` and exists (select * from `articles` where `order_items`.`article_id` = `articles`.`id` and `manufacturer_id` = ?)) and `order_items`.`tariff_id` is not null and `orders`.`created_at` between ? and ? group by `order_date` order by `order_date` asc
#null_order_count
select count(*) null_order_count, DATE_FORMAT(orders.created_at, "%Y-%m-%d") as order_date from `orders` inner join `order_items` on `order_items`.`order_id` = `orders`.`id` where exists (select * from `order_items` where `orders`.`id` = `order_items`.`order_id` and exists (select * from `articles` where `order_items`.`article_id` = `articles`.`id` and `manufacturer_id` = ?)) and `order_items`.`tariff_id` is null and `orders`.`created_at` between ? and ? group by `order_date` order by `order_date` asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment