use Northwind
Go
select
dbo.Orders.OrderID
,Cast(dbo.Orders.OrderDate As DATE)Order_Date
, dbo.Customers.CustomerID
, dbo.Customers.CompanyName
, dbo.Products.ProductName
, Cast(dbo.Orders.ShippedDate As DATE) As Ship_Date
, dbo.[Order Details].UnitPrice
, dbo.[Order Details].Quantity
, dbo.[Order Details].UnitPrice * Quantity As Sub_Total
, dbo.[Order Details].Discount
, (dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity) * (dbo.[Order Details].Discount) As Discount_Amount
, (dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity) * (dbo.[Order Details].Discount) As total_Amount -- fix this
, dbo.Orders.Freight
, (dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity) * dbo.[Order Details].Discount +
(dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity) + dbo.Orders.Freight As Grand_total --fix this
from dbo.Orders
inner join dbo.Customers on dbo.Customers.CustomerID = dbo.Orders.CustomerID
inner join dbo.[Order Details] on dbo.Orders.OrderID = dbo.[Order Details].OrderID
inner join dbo.Products on dbo.[Order Details].ProductID = dbo.Products.ProductID
where dbo.orders.ShippedDate is not null and(dbo.orders.ShippedDate >= '1996')
Order by dbo.Orders.ShippedDate Asc
I cannot use the alias field names as part of additional calculations for new columns.
total_Amount and Grand_Total cannot be done with my skill level.