Skip to content

Instantly share code, notes, and snippets.

@nfriend21
Last active July 10, 2023 12:31
Show Gist options
  • Save nfriend21/062629c9c360996542d2595c5dd7b22f to your computer and use it in GitHub Desktop.
Save nfriend21/062629c9c360996542d2595c5dd7b22f to your computer and use it in GitHub Desktop.
Order.where('created_at >= ? AND created_at < ?', '2021-01-01', '2022-01-01').where('payment_status = ?', 'Paid').count
Order.where('created_at >= ? AND created_at < ?', '2022-01-01', '2023-01-01').where('payment_status = ?', 'Paid').count
#all 2021 order quantity
Order.where('created_at >= ? AND created_at < ?', '2021-01-01', '2022-01-01').where('payment_status = ?', 'Paid').count
#all 2022 order quantity
Order.where('created_at >= ? AND created_at < ?', '2022-01-01', '2023-01-01').where('payment_status = ?', 'Paid').count
#all 1H 2022 order quantity
Order.where('created_at >= ? AND created_at < ?', '2022-01-01', '2022-07-01').where('payment_status = ?', 'Paid').count
#all 1H 2023 order quantity
Order.where('created_at >= ? AND created_at < ?', '2023-01-01', '2023-07-01').where('payment_status = ?', 'Paid').count
#all 1H 2022 order total sum
Order.where('created_at >= ? AND created_at < ?', '2022-01-01', '2022-07-01').where('payment_status = ?', 'Paid').sum(:total).to_f
#all 1H 2023 order total sum
Order.where('created_at >= ? AND created_at < ?', '2023-01-01', '2023-07-01').where('payment_status = ?', 'Paid').sum(:total).to_f
#all 2021 order total sum
Order.where('created_at >= ? AND created_at < ?', '2021-01-01', '2022-01-01').where('payment_status = ?', 'Paid').sum(:total).to_f
#all 2022 order total sum
Order.where('created_at >= ? AND created_at < ?', '2022-01-01', '2023-01-01').where('payment_status = ?', 'Paid').sum(:total).to_f
#no print studios 2021
Order.joins(:website).where('websites.core_business_type != ?', 'print_studio').where('orders.created_at >= ? AND orders.created_at < ?', '2021-01-01', '2022-01-01').where('orders.payment_status = ?', 'Paid').count
#no print studios 2022
Order.joins(:website).where('websites.core_business_type != ?', 'print_studio').where('orders.created_at >= ? AND orders.created_at < ?', '2022-01-01', '2023-01-01').where('orders.payment_status = ?', 'Paid').count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment