Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

help with SQL queries

Tags:

sql

mysql

Given the following diagram:

enter image description here

Right now I have queries to find out how much each member has donated and also listing those donations in a list for each member. Now I want to query the donations table to get the results divided up by each organization.

Something like:

enter image description here

Can someone please help me with this SQL?

like image 315
enfield Avatar asked Nov 23 '25 14:11

enfield


1 Answers

Assuming that you're using MySQL:

SELECT
    MemberId,
    OrganizationId,
    SUM(Amount) AS `Amount Donated to Organization`,
    COUNT(Amount) AS `Number of Donations`
FROM
    Donations
GROUP BY
    MemberId,
    OrganizationId
;
like image 159
Daniel Wolfe Avatar answered Nov 25 '25 04:11

Daniel Wolfe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!