sql - SUM DISTINCT VALUE ON JOIN -
order_id ========= id price 10 10 b 20 b 20 c 30 c 30 d 40 d 40 client ================== client name id 1 clientinc. 1 clientinc. 1 clientinc. b 1 clientinc. b 1 clientinc. c 1 clientinc. c 1 clientinc. d 1 clientinc. d
i have 2 tables need join (order_id , client) , want sum price distinct order_id , create report below:
desired solution ======================== id name sum(price) 1 clientinc. 100
this current query using:
select merchant, name, sum(price) order_id join client b on a.id = b.id group merchant, name
it displaying following output summarizing every order_id, problem want sum distinct order id:
current wrong report ====================== id name sum(price) 1 clientinc. 200
select merchant, name, sum(price) ( select distinct id,price order_id ) join client b on a.id = b.id group merchant, name;
wiki
Comments
Post a Comment