sql - db2 specific query for count of distinct rows -
i using db2. have query:
select distinct order_number, trdm trademark, cmdnsm customer_name db1.ordfa join db2.ccadf on sford# = wdrso join db2.dada06 on wd3adf = wd3fla join db1.cmp1 on c1lk2 = sf2lk year = '14' , part = '5484' order customer_name, trademark
and result set above query
order_number trademark customer_name 2220824. air epr products inc 2254614. avalon epr products inc 2214146. avalon epr products inc 2338002. avalon epr products inc 2102733. boss epr products inc 2286148. cdc epr products inc 2116148. cdc epr products inc 2032105. hc summlc 2014046. hc summlc 2232312. sdexo summlc 2267369. sdexo summlc 2085280. sdexo summlc 2170433. sdexo summlc 2179283. sdexo summlc 2378745. sdexo summlc
what need db2 query give me result set:
num_orders trademark customer_name 6 sdexo summlc 3 avalon epr products inc 2 cdc epr products inc 2 hc summlc 1 boss epr products inc 1 air epr products inc
if db2 supports ansi standard sql believe need add acount
andgroup by
:
select count(distinct order_number) num_orders, trdm trademark, cmdnsm customer_name db1.ordfa join db2.ccadf on sford# = wdrso join db2.dada06 on wd3adf = wd3fla join db1.cmp1 on c1lk2 = sf2lk year = '14' , part = '5484' group trdm, cmdnsm order num_orders desc, customer_name, trademark
Comments
Post a Comment