sql - How to get DB records which have different value of same column in same table -
please take of below sql:
select top 3 acct_num acct_package package_key in ( select package_key acct_serv serv_id = 'a1' , package_key in ( select package_key acct_serv serv_id = 'b1' , package_key in( select package_key acct_serv serv_id = 'c1' ) ) )
in case, no other tables had relationship.
i can retrieve data need above sql, guess maybe have other coding more effective.
many helping!!!
this approach (please remember use order when use top xx, otherwise result not predictable) (i tried on oracle db, without top of course):
select top 3 acct_num acct_package inner join (select package_key, sum(rc) sum_tot (select package_key, serv_id, 1 rc acct_serv serv_id in ('a1','b1','c1') group package_key, serv_id ) b group package_key ) c on a.package_key = c.package_key sum_tot >=3 order a.package_key;
Comments
Post a Comment