- 11-24-2009 05:11 AM #1
what will be the return value of COUNT(*) if no records were selected by the group by Hi,
i have a query like this
select field1,count(*) from table1 where field1 in(5,3,7) group by field1
i want zero to be displayed incase of no rows retrieved for the field1 values.
field1 count(*)
5 12
3 15
7 0
can any of you plese help me on this?
Thanks
- Club-Oracle Complementary E-Books and Magazines
Get your free Complementary Copy of Oracle Magazine
You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.
- 11-24-2009 07:58 AM #2
Re: what will be the return value of COUNT(*) if no records were selected by the grou Code :
SQL> SELECT FIELD1,COUNT(*) FROM TABLE1
2 GROUP BY FIELD1
3 ORDER BY 1
4 /
FIELD1 COUNT(*)
---------- ----------
3 15
5 12
2 rows selected.
SQL> SELECT FIELD2,
2 COUNT(FIELD1)
3 FROM TABLE1 A
4 FULL OUTER JOIN (SELECT 3 FIELD2
5 FROM DUAL
6 UNION ALL
7 SELECT 5
8 FROM DUAL
9 UNION ALL
10 SELECT 7
11 FROM DUAL) B
12 ON A.FIELD1 = B.FIELD2
13 GROUP BY FIELD2
14 ORDER BY 1
15 /
FIELD2 COUNT(FIELD1)
---------- -------------
3 15
5 12
7 0
3 rows selected.Thanks,
Sikki
- 11-25-2009 08:14 AM #3
Re: what will be the return value of COUNT(*) if no records were selected by the grou Thank u very much..
Similar Threads
-
how to update Physical count in inventory module?
By oraclelux in forum Oracle SCMReplies: 3Last Post: 01-18-2010, 10:47 AM -
Listing all Count Dates from the MTL_CYCLE_COUNT_ENTRIES_V table
By RJAYE in forum SQL PL/SQLReplies: 3Last Post: 10-13-2009, 07:04 PM -
Comparison of records in a table using cursors
By lakshmi_9078 in forum SQL PL/SQLReplies: 2Last Post: 07-08-2009, 12:28 PM -
unable to display records in sql*plus fetched through cursor
By laxman in forum SQL PL/SQLReplies: 4Last Post: 07-08-2009, 06:39 AM -
distinct count query
By hiswapna in forum SQL PL/SQLReplies: 1Last Post: 05-05-2009, 05:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
