sql - Query for Select Id,name,Cost on Delivery using sub query -


i want make 1 query selecting customer id, cus_name, total cod orders. made these 2 queries ,but these queries calculating cod , non cod separately. how make single query using sub query.

select o.cust_id, upper(c.name), count(o.order_no) 'total cod orders' t_acct_companyprofile c inner join      t_inv_order o      on c.id = o.cust_id c.type_id = 1 , o.cod = 1 group o.cust_id, c.name;  select o.cust_id, upper(c.name), count(o.order_no) 'total cod orders' t_acct_companyprofile c inner join      t_inv_order o      on c.id = o.cust_id c.type_id = 1 , o.cod = 0 group o.cust_id, c.name; 

with conditional aggregation:

select o.cust_id,         upper(c.name),         sum(case when o.cod = 1 1 else 0 end) 'total cod orders',        sum(case when o.cod = 0 1 else 0 end) 'total non cod orders'  t_acct_companyprofile c inner join t_inv_order o on c.id = o.cust_id c.type_id = 1 group o.cust_id, c.name 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -