I'm not looking for others to do my homework, I just want help with getting an idea one what to do.

My class was given an assignment and one of the questions is:

Create a query that will show the order id, item id, price, sales tax and subtotal for all items in the order item table. Create column aliases to describe the sales tax and subtotal columns. Only include in your output those items that
sold for $20 or more. Order your output by order id. Your output should look like the following:

orderid Item ID Price Sales Tax Subtotal

1004 1004 32.50 1.9500 34.4500
1016 1020 47.95 2.8770 50.8270
1018 1018 47.50 2.8500 50.350

Here is what I got so far:

select *
,cast(round((price) * 0.06, 4)as numeric(6,4)) as [Sales Tax]
--,cast(price as varchar(10)) as [Subtotal]
,cast(price + [Subtotal] as varchar(20)) as [Subtotal]
from order_item
where price >= 20
order by orderid asc;

I don't know what I'm doing wrong. I got everything else correct, but I am stumped at the part with finding the subtotal, would someone be able to give me an idea on what I should do?

Recommended Answers

All 3 Replies

How do you combine subtotal? Is it by item ID? order ID? In other words, what are you grouping in order to calculate subtotal???

Hello,

Ok first thing is stop using "SELECT * " when you don't need every field from the table and second what you can do is simply multiply the price times 1 plus the sales tax (i.e 1.06 in your code) because the equation can be simplified algebretically to:

Subtotal = (price * 1.00 ) + (price * 0.06)
Subtotal = (price * (1.00 + 0.06))
Subtotal = (price * 1.06)

you can always SELECT SUM()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.