sql - Return 10% of records for each group that meet a certain criteria -
i trying query table has multiple groups 10% of systems in each group meet criteria.
here's data:
create table tablename select '4fh6v1' computername, 'az1' location, '3093' rating dual union select '0glyq1' computername, 'az1' location, '3093' rating dual union select 'p191r1' computername, 'az1' location, '3093' rating dual union select '7cmj02' computername, 'az3' location, '3392' rating dual union select '8w2qs1' computername, 'az4' location, '3093' rating dual union select 'k9chx1' computername, 'az7' location, '3192' rating dual union select '3xzns1' computername, 'az7' location, '3093' rating dual union select '79rgx1' computername, 'az9' location, '3192' rating dual union select '02br22' computername, 'az3' location, '2593' rating dual ; | computername | location | rating | |--------------|----------|--------| | 4fh6v1 | az1 | 3093 | | 0glyq1 | az1 | 3093 | | p191r1 | az1 | 3093 | | 7cmj02 | az3 | 3392 | | 8w2qs1 | az4 | 3093 | | k9chx1 | az7 | 3192 | | 3xzns1 | az7 | 3093 | | 79rgx1 | az9 | 3192 | | 02br22 | az3 | 2593 |
there many more records in table. example, need find 10% of computer names in each location have rating of 3093.
if using sql server can use percent
in select
statement:
select top 10 percent * tablename rating=3093;
Comments
Post a Comment