sql - Mysql wrong syntax -


an example:

select avg(cost) items seller_id=6 

lets want find average cost of items seller 6 , average cost of items seller 10. need in 1 sql. when seller_id = 6 , 7. gives me average cost of 6 , 7. want average of 6 , average of 7.

this actual question: our orders have 5 priorities: "1-urgent", "2-high", "3-medium", "4-not spec", "5-low". type of orders has highest sum of ‘total price’?

my sql:

select sum(o_totalprice) orders `o_order-priority`='1-urgent' , '2-high' , "3-medium" , "4-not spec" , "5-low" 

select seller_id,avg(cost) items  seller_id in (6,10) group seller_id 

and if want sellers remove seller_id in (6,10) clause

sql fiddle 2 sellers

sql fiddle sellers

edit based on question's edit

select o_order-priority, sum(o_totalprice) total orders group o_order-priority order total desc limit 1 

that gives o_order-priority has maximum sum. , if remove limit, gives total sum priorities.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -