0

enter image description here

I have a hard time calculating the items.sell_price by the bill id.

This is my query.

    select bill.name,sum(item.sell_price) as 'price' 
    from bills,bill_information,items 
    where bills.id_bill = bill_information.bills_id 
      and 
          bill_information.item_id = item.id_item

But the problem is the sum doesn't work the way I want. I want to sum the sell_prices in table items when bills.id_bill has two item_id in the bill_information.

If we have two item_id in bill_information I want it to sum just those two, not all the sell_price in the items table

:( hope you get it

2
  • Why "WITHOUT join's"? The syntax you're using includes JOINS, but using the comma syntax. Commented Jun 14, 2021 at 23:06
  • @TangentiallyPerpendicular I removed it from the title, I found them posts here that uses left join but that don't work for me, that's why Commented Jun 14, 2021 at 23:39

1 Answer 1

1

what is the table is doesn't matter in this case you have to do only one thing. please group by the bill id like below,

select bill.name,sum(item.sell_price) as 'price' 
from bills,bill_information,items 
where bills.id_bill = bill_information.bills_id 
and 
bill_information.item_id = item.id_item
GROUP BY bills.id_bill

the new part is,

GROUP BY bills.id_bill
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.