If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > group by query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-03, 15:26
mojojo82 mojojo82 is offline
Registered User
 
Join Date: Jul 2003
Posts: 21
group by query

Hi

I have the following query:

select tbl.id, nvl(sum(x),0) as A, nvl(count(y),0) as B from .... where tbl.id in (1,2,3) group by tbl.id

And here are the results I am currently seeing:

tbl.id A B
1 232 343
3 3434 343

The table where tbl.id=2 has 0 for both columns so it does not show up.
How can I modify the query so that I will get a result set as the following:

tbl.id A B
1 232 343
2 0 0
3 3434 343
Reply With Quote
  #2 (permalink)  
Old 08-25-03, 21:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
> "The table where tbl.id=2 has 0 for both columns so it does not show up"

i'm having trouble believing this

your query must return a row for the 2 group, regardless of whether the 2 row(s) have 0 in the x and/or y columns, or nulls, or anything else

if at least one row for 2 exists, there will be a 2 group in the results, unless it's eliminated by a HAVING clause

rudy
http://r937.com/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On