join - SQL CASE STATEMENT in COUNT CLAUSE -
I am trying to get the name of a product and the number of my sales from two separate tables.
My table looks like this:
book Book_ID | Book_Title | Book_Author SOLD Transaction_ID | Book_ID | Customer_ID I can get most of the results from the following query
SELECT b.Book_Title, COUNT (s.Book_ID) from Book b, SOLD S WHERE B.Book_ID = s.Book_ID Group by BBookBookTitle; However, it only displays products with at least one sale. I would like to display all the products, if there is no sale, will show zero. I am walking with something like this:
SELECT b.Book_Title, COUNT (case when S. Book_ID is zero, then 0 s book_id-ind), from book B, radiation Ou b. Book_ID = s.Book_ID GROUP BY Book_Title; But WHERE is blocking results to people with volume 1 or more sales.
Can someone recommend some way about this? I'm using Oracle 10G.
Thanks
Use a left external join:
< Pre> SELECT b.Book_Title, from the COUNT (s.Book_ID) book External join b.Book_ID = s.Book_ID GROUP by b.Book_Title;
Comments
Post a Comment