memphisTNdev22
Programmer
How can I select a different number of records for different data within a column..For example...i need to select 50 records where type = 'A', 100 records where type = 'B', and 25 records where type = 'C'
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'A')
WHERE ROWNUM <= 50
UNION
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'B')
WHERE ROWNUM <= 100
UNION
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'C')
WHERE ROWNUM <= 25
ORDER BY <whatever order you want for the results>;
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'A')
WHERE ROWNUM <= (select .27*count(*) from <source_table> WHERE type = 'A')
UNION
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'B')
WHERE ROWNUM <= (select .36*count(*) from <source_table> WHERE type = 'B')
UNION
SELECT <expression_list>
FROM (SELECT * FROM <source_table> WHERE type = 'C')
WHERE ROWNUM <= (select .36*count(*) from <source_table> WHERE type = 'C')
ORDER BY <whatever order you want for the results>;