Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySql query for Joining two tables to get result from 2nd table in reference

I have two tables Order and Transaction

Order Table

id OrderId TransId OrderDate
1 54 11551 01-12-2021
2 55 11552 02-12-2021
3 56 11553 02-12-2021
4 57 11554 05-12-2021
5 58 11555 08-12-2021
6 59 11556 09-12-2021

Transaction Table

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

id TransId OrderId PaymentMethod Amount
1 11551-1 54 Cash 1000
2 11552-1 55 Cash 500
3 11552-2 55 Card 200
4 11553-1 56 Cash 500
5 11553-2 56 Card 200
6 11553-3 56 UPI 100

Here we have 3 Transaction methods Cash, Card and UPI.

I want to get total Amount collected using Cash as PaymentMethod done for period 01-12-2021 to 08-12-2021 in orderDate of Order Table

>Solution :

select t.paymentMethod, sum(t.amount) from tbl_order o
inner join tbl_transaction t on o.orderId = t.orderId 
where t.paymentMethod = 'CASH' and o.orderDate between start_date and end_date
group by t.paymentMethod;   
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading