mysql - Multiple criteria with count of matches -


i have 2 tables, table of people peopleid , name, , table of pledges have made has pledgeid (1 6) personid came from, , amount field.

we need have query gives distinct list of people, how have pledged in total, , number of pledges have got correct (pledgeids 1,3 , 5 regarded correct)

so need know example john smith has pledged £500 in total , matched 2 pledges (because had made pledges on 1,3 , 6 example) , sally james has pledged £2000 , has pledged on ids 1,3 , 5 , has therefore matched 3

i hope clear. appreciate one.

many thanks

dave

sounds work:

select personid,     sum(amount) totalpledged,     sum(case when pledgeid in (1,3,5) 1 else 0 end) correctpledges personpledges group personid 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -