Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Count the numbers that are used in range - SQL

800012Sep 24 2010 — edited Sep 24 2010
Dear Guru's,

I need a help to create a query.

My INPUT will be like


WITH s AS
(
SELECT 2 a, 7 b
FROM DUAL
UNION
SELECT 3 a, 3 b
FROM DUAL
UNION
SELECT 3 a, 6 b
FROM DUAL
UNION
SELECT 9 a, 15 b
FROM DUAL
UNION
SELECT 10 a, 10 b
FROM DUAL
UNION
SELECT 10 a, 15 b
FROM DUAL)
SELECT *
FROM s;

I need output like the distinct count of numbers. Consider column a as num_from and b as num_to. So the expected output here is 13. since all the numbers from 2 to 15 are in use expect 8. so my result would be 13. Kindly help me to reslove.

I am currently working in Oracle 10g database.

Thanks In Advance!

With Best Regards,
VJ
This post has been answered by odie_63 on Sep 24 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2010
Added on Sep 24 2010
2 comments
602 views