Tuesday, 15 April 2014

sql - Alternative query -



sql - Alternative query -

is there alternative way write query?

select * (select countries.country_name, sum( profits.amount_sold) profits total outer bring together customers on profits.cust_id = customers.cust_id total outer bring together countries on customers.country_id = countries.country_id country_name = 'japan' grouping countries.country_name )

thanks in advance

looking @ current query, looks outer select unnecessary. also, since aggregating on rows, don't need total outer joins. if want different way simplify query, should able use:

select countries.country_name, sum(profits.amount_sold) profits, customers, countries profits.cust_id = customers.cust_id , customers.country_id = countries.country_id , countries.country_name = 'japan' grouping countries.country_name;

and finally, since query filters single row (country_name='japan'), don't need grouping by, if you're sure have @ to the lowest degree 1 row:

select 'japan' country_name, sum(profits.amount_sold) profits, customers, countries profits.cust_id = customers.cust_id , customers.country_id = countries.country_id , countries.country_name = 'japan';

sql oracle11g

No comments:

Post a Comment