Need SQL query in Access to Show Total Sales by Catalog# - sql

I have a table named Sales_Line_Items. In it I have the following fields; order#, Catalog#, Whole_Sale_Price, Qty_Ordered. I have created a query using this table that sums up the Qty_Ordered field and returns a Revenue field with a total per order line. What I need is a query that shows me each the quantity of each item sold and the total sales by item. This is the query I wrote for the total revenue:
SELECT
Sales_Line_Items.[Order#],
Sales_Line_Items.[Catalog#],
Sales_Line_Items.Wholesale_Price,
Sum(Sales_Line_Items.Qty_Ordered) AS SumOfQty_Ordered,
Sum(Sales_Line_Items.[Qty_Ordered]*Sales_Line_Items.[Wholesale_Price]) AS Revenue
FROM Sales_Line_Items
GROUP BY
Sales_Line_Items.[Order#],
Sales_Line_Items.[Catalog#],
Sales_Line_Items.Wholesale_Price;
The result was a new field with header ' Revenue'. The other fieds listed are Order#, Catalog#, Wholesale_Price, and SumofQty_Ordered fields. This is fine, if I want to know what every sales line totals up to within each order. But I want to show the total sold by Catalog# so that I can view each product sales total.

I was able to figure this out by adding the Totals line in Design View, and grouping by Expression in the query field and leaving the Catalog# field alone. The query I used looks like this;
Total: Sum([Sales_Line_Items]![Wholesale_Price]*[Sales_Line_Items]![Qty_Ordered])

Related

Can't get A sum to join to a table

I have two tables, one contains a set of line items with amounts:
LEDGERTRANS:
Invoice ID LineAmount
CM-00011054 -122.500000000000
CM-00011054 -246.000000000000
CM-00011054 -159.840000000000
CM-00011054 -39.3600000000000
And one with an item number i want, which happens to have a field, AMOUNTMST that is the sum of the above amounts
CUSTINVOICETRANS
INVOICE ID AMOUNTMST
110100 -567.700000000000
400100 567.700000000000
I would like to take the sum of the CustInvoiceTrans lines, then grab the corresponding invoice id from the LedgerTrans Table.
This is for SQL Server 2008R2.
As I said, all I want is the InvoiceId. I think i'm making this too complicated. any help appreciated

How to calculate new value for field in Access

I've got a few problems with a database I have created.
I want to calculate a Total Price (Sandwich Quantity multiplied by Sandwich Price). I had it working before, but I had to delete Sandwich Price from the OrderDetailsT table of which it was originally in. I'm now having issues with this calculation, as I cannot make a calculation in the OrderDetailsT table (Sandwich Price isn't there).
How can I apply the Discount to the Total Price if the Total Price is more than $50 for instance? After the Discount has been applied to the Total Price field, I would also like to store it in the NewPriceAfterDiscount field.
Here is an image detailing my situation:
You have multiple questions in one:
But, first of all. As the image shows, why do you have a left join between OrderDetails an Sandwich? In a order calculation you don't need not ordered sandwiches.
To total price calculation:
Add a new column to the query grid (assuming discount is a percentaje stored has a number between 0 and 1):
[SandwichT].[SandwichPrice] * [OrderDetailT].[SandwichQuantity] * [OrderDetailT].[Discount]
To store total price: you can use the above formula, but using a update query.
If you plan to show the prices in a form or in a report:
you can do de calculations on the fly (and don't store the total
price)
or you should update the total price un one query and then build another
query as datasource of the form/report.
another posibility (my recomendation) is to store the total in the input form

Create one query with sum and count with each value pulled from a different table

I am trying to create a query that pulls two different aggregated values from three different tables during a specific date range. I am working in Access 2003.
I have:
tblPO which has the high level purchase order description (company name, shop order #, date of order, etc)
tblPODescription which has the dollar values of the individual line items from customers the purchase order
tblCostSheets which as a breakdown of the individual pieces that we need to manufacture to satisfy the customers purchase order.
I am looking to create a query that will allow me, based on the Shop Order #, to get both the sum of the dollar values from tblPODescriptions and the count of the different type of pieces we need to make from tblCostSheets.
A quick caveat: the purchase order may have 5 line items for a sum of say $1560 but it might take us making 8 or 9 different parts to satisfy those 5 line items. I can easily create a query that pulls either the sum or the count by themselves, but when I created my query with both, I end up with numbers that are multipled versions of what I want. I believe it is multiplying my piece counts and dollar values.
SELECT DISTINCTROW tblPO.CompanyName, tblPO.ShopOrderNo, tbl.OrderDate, Sum(tblPODescriptions.ItemAmount) AS SumOfItemAmount, Count(tblCostSheets.Description) AS CountOfDescription
FROM (tblPO INNER JOIN tblPODescriptions ON (tblPO.CompanyName = tblPODescriptions.CompanyName) AND (tblPO.PurchaseOrderNo = tblPODescriptions.PurchaseOrderNo) AND (tblPO.PODate = tblPODescriptions.PODate)) INNER JOIN tblCostSheets ON tblPO.ShopOrderNo = tblCostSheets.ShopOrderNo
GROUP BY tblPO.CompanyName, tblPO.ShopOrderNo, tblPO.OrderDate
HAVING (((tblPO.OrderDate) Between [Enter Start Date:] And [Enter End Date:]));

After executing a SQL statement, i get a column of data. How can I get a total of that data?

I am running a query to retrieve a list of invoices that have not been approved yet. This query is generating daily alerts via email. The email contains an HTML table of the client name, inv #, sub-total, adjustments, final total. I want to be able to list a summary before the table of the total sub-total, total adjustments, and total final total of the entire table.
ex:
Total Sub-total: 10
Total Adj: -8
Total Billed: 2
Sub-Total Adj Total
7 -6 1
3 -2 1
I tried SUM(sub-total), but it only retrieves the first sub total ("7" in this example) instead of adding them all up. Help?
The query I am using is:
SELECT dbo.CurInv.subtotal AS "subtotal", dbo.CurInv.CIAdj AS "Adj",
dbo.CurInv.CIAdj+dbo.CurInv.subtotal+dbo.CurInv.CISTax AS "TotalInvoice",
SUM(dbo.CurInv.CIAdj) AS "Total Write Up(Down)"
FROM dbo.Clients, dbo.CurInv
I ended up just creating a new table that calculated the totals for each row and then added that table to the query.
You can used the UNION operator. You need to define a column to designate the individual vs total data.
SELECT
dbo.CurInv.subtotal AS "subtotal",
dbo.CurInv.CIAdj AS "Adj",
dbo.CurInv.CIAdj+dbo.CurInv.subtotal+dbo.CurInv.CISTax AS "TotalInvoice",
SUM(dbo.CurInv.CIAdj) AS "Total Write Up(Down)"
FROM
dbo.Clients, dbo.CurInv
UNION
SELECT
SUM(dbo.CurInv.subtotal) AS "subtotal",
SUM(dbo.CurInv.CIAdj)AS "Adj",
SUM(dbo.CurInv.CIAdj+dbo.CurInv.subtotal+dbo.CurInv.CISTax) AS "TotalInvoice",
SUM(dbo.CurInv.CIAdj) AS "Total Write Up(Down)"
FROM
dbo.Clients, dbo.CurInv

SQL Query For Product Sales Report

I have a query that gives a product sales report by whatever date range I specify.
Something like select whatever from wherever where date ordered between start date and end date order by product id.
My page then loop through the recordset and displays the results on the page in a list.
What I would like to do is provide a list showing PRODUCT A total sales = whatever, PRODUCT B total sales = whatever so on and so forth. So as the loop runs product a = product a + 1
I do this already with staff sales, but there are only 5 staff so I have managed to do this, but there are over 300 product codes.
What is the best way to proceed.
Possible solutions:
Do this in your application code by keeping track of the product code and running totals. When the product code changes, emit an extra row with the totals into the output.
Do something similar to #1, but use a separate GROUP BY query to get the totals.
Create a SELECT statement that UNIONs together two queries, one for the product detail lines and one with the summary information.
Use some product specific command (you don't say what database you're using) to accomplish #3 without having to do the UNION yourself. Both MySQL and SQL Server offer (different) ROLL UP clauses that can do what you want.