Select data from one table that depends on values from another table in mysql

Muntashir Are Rahi

I have two tables. First one is conversion_earnings and second on is vloer_sales_orders

enter image description here

enter image description here

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.

Fahmi

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.

edited at
0

Comments

0 comments
Login to comment

Related

MYSQL, copy data from one table to another table with increment in varchar

MySQL SELECT with data from another table

How to copy data from one table to another new table in MySQL?

MSSQL Select column values from one table to another table

TSQL - Select column values from one table to another one

How to select data from one table and select count to another table and combine it in MySQL?

MySQL: "Patch" existing data on a table from values in another table

Retrieve data from one table and insert/update in another table in mysql

How to automatically load values from one table column to another in MYSQL

mysql insert from one table to another based on select

Append data from one table to another table

Moving data from one mysql table to another

Move data from one MySQL table to another

How to Replace and Update Data From One Table to Another Table in MySQL

MySQL: Is there a way to insert values from one table to another?

How to select data from a table by referring to another table in MySQL

Select from one table and count from another

Insert Data From One Table to Another Table with default values

MySQL add data from one table to another

Copy Data from one table to another table

Select data from one table with the conditions from another

SELECT get values from one parent table given values from another parent table using junction table

MySQL query - select from one, count from another table

Insert Data From One Table to Another Table and Add New Values

Insert Data From One Table To Another - MySQL

MYSQL problem: How to add values from one table to another

MySql: Insert data from one table to another

mysql insert into select join - copy values from one column to another table, passing through a connecting table

MySQL : Updating table with values from another table