I have two tables. First one is conversion_earnings
and second on is vloer_sales_orders
I need to get the sum of the installer_paid_amount
of every installer_id from conversion_earning
table based on selected created_on
timestamps from vloer_sales_orders
table where order_id is a match in both the tables. I tried the following query:
SELECT DISTINCT ce.installer_id, SUM(ce.installer_paid_amount) as sum_installer
FROM conversion_earning INNER JOIN vloer_sales_orders so
on ce.order_id = so.order_id
WHERE ce.vendor_family_id = '10' AND ce.invoice_for = 'Installer' AND
ce.installer_id !='' AND so.created_on between '2019-12-01' AND '2020-01-21'
group by ce.installer_id
ORDER BY SUM(ce.installer_paid_amount) DESC
I am getting sql error. How to proceed. Thanks in advance.
You can try below - u are missing allias for table conversion_earning and u don't need distinct here since you are using group by
SELECT so.installer_id, SUM(ce.installer_paid_amount) as sum_installer
FROM conversion_earning ce INNER JOIN vloer_sales_orders so
on ce.order_id = so.order_id
WHERE ce.vendor_family_id = '10' AND ce.invoice_for = 'Installer' AND so.installer_id !='' AND so.created_on between '2019-12-01' AND '2020-01-21'
group by so.installer_id
ORDER BY sum_installer DESC
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments