mysql - Apply DISTINT on the JOIN table is not working -
my query summing fee based on woks table (which 3 parts) result should 13000 getting 39000.
# order table ------------------------------------------- | id | order | name | fee | ------------------------------------------- | 1 | select statement | ab | 13000 | ------------------------------------------- # work table ----------------------------- | id | user id | order id | ----------------------------- | 1 | 123 | 1 | | 2 | 123 | 1 | | 3 | 123 | 1 | ----------------------------- # query select o.order_id, sum(o.fee) total_words users u left join works wr on wr.user_id = u.id left join orders o on o.order_id = wr.order_id u.id = 123 # output => array ( [order_id] => 1 [fee] => 39000 )
i have tried distinct , group same result.
select `user_id`, sum(orders.`fee`) (select distinct `user_id`, `order_id` works ) user_work join orders on user_work.`order_id` = orders.`id` user_work.user_id = 123
output
| user_id | sum(orders.`fee`) | |---------|-------------------| | 123 | 13000 |
Comments
Post a Comment