0

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?

Edited by ZombieKnight93

4
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by daniellemacey
0

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

0

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)

Edited by rch1231

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.