DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   Simple query (http://www.daniweb.com/forums/thread122593.html)

dave.respawn May 5th, 2008 3:34 pm
Simple query
 
Hi,
im going back through some SQL questions for my exams next week and I cant find a soloution for this, anyone help out?

Do a report using SQL that lists the names of categories from which items were bought. For each category the report should show the total value of the purchases (excluding VAT) and the total value of the VAT paid.. Exclude those categories where the total value of the purchases (excluding VAT) is less than €100.

Country(c_id, c_name, c_vat_rate, exchange_rate)
Seller(seller_id, seller_name, c_id)
Category(cat_id, cat_name)
Purchase(p_id, p_date, seller_id)
Purchase_item(p_id, item_name, cat_id, item_price, item_qty)
Fig. 1 Logical Schema

manoshailu May 6th, 2008 2:25 am
Re: Simple query
 
hi,

Try the Below Query:

select c.cat_name,sum(pi.item_price * pi.item_qty) as total, c.c_vat_rate * total
from category c , purchase p,puchase_item pi,country co,seller s
where p.p_id=pi.p_id and c.cat_id=pi.cat_id and total>100
and co.c_id=s.c_id and s.seller_id=p.seller_id
group by c.cat_name,c.vat_rate


Shailaja


All times are GMT -4. The time now is 3:48 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC