April 9, 2009 at 8:13 pm
I am learning to become a DBA and I am trying to write a simple query and need help.
I have a table with invoice numbers and entityid numbers and expped expense period. An entityid like entityid = '600' can have many invoices for a period. Furthermore, there may be many invoice numbers that are the duplicates so the table will look like this
entityid invoice expped
600 123 200801
600 123 200801
600 123 200801
600 555 200801
600 555 200801
600 888 200801
601 222 200801
601 222 200801
601 333 200801
I need to count the number of invoices for each entity in one period, so my result will look like
entityid Num of Invoice
600 3
601 2
Please help
Jeff
April 9, 2009 at 8:23 pm
SELECT entityid, COUNT(DISTINCT INVOICE) FROM [YOUR TABLE] GROUP BY entityid
Hang Deok Cho.
hyemang@gmail.com
DBA
April 9, 2009 at 8:29 pm
SELECT entityid, COUNT(DISTINCT INVOICE) FROM [YOUR TABLE] GROUP BY entityid
Thank you.
Hang Deok Cho.
hyemang@gmail.com
DBA
April 10, 2009 at 12:01 am
hyemang (4/9/2009)
SELECT entityid, COUNT(DISTINCT INVOICE) FROM [YOUR TABLE] GROUP BY entityid
hey if u want invoices period wise then just add period to query
SELECT entityid, COUNT(DISTINCT INVOICE),expped
FROM [YOUR TABLE] GROUP BY
entityid,expped
April 12, 2009 at 5:44 pm
Thanks. Cannot believe that i could not figure it out. It was simple and I tried very hard.
Thanks Again
Jeff
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply