I'm trying to pull together a table which shows the summary of invoice totals by invoice number and customer code. I think I have it mostly down but when I try to summarize the line item prices which would give an invoice total, I get the parameter value input box for the line_price field.
When you go into the table, the first layer of data has invoice number and customer code. From there, you can drill in and you get line item numbers per invoice and the total value per line. I need to sum that total value per line and show it at the customer code and invoice number level.
Below is what I have so far:
SELECT CUS_CODE, INV_NUMBER, SUM(LINE_PRICE) AS InvoiceTotal
FROM INVOICE
GROUP BY CUS_CODE, INV_NUMBER;
You must include the subdata, the invoice lines' table, like this:
SELECT
CUS_CODE, INV_NUMBER, SUM(LINE_PRICE) AS InvoiceTotal
FROM
INVOICE
INNER JOIN
INVOICE_LINE
ON INVOICE.ID = INVOICE_LINE.INVOICE_ID
GROUP BY
CUS_CODE, INV_NUMBER;
Related
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])
I am trying to add everything in te data (dollar_value_us, QUANTITY) but not add shipping total since each transaction number has multiple items but the customer only paid shipping once. I am using the below data:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=01693db7ce05b062804cedeb3b3a7e73
below is the query which I am using on my actual databse:
select QUARTER_DATE ,COUNTRY,sum(DOLLAR_VALUE_US), sum(QUANTITY), max(SHIPPING_TOTAL)
from transaction_detail_mv
group by QUARTER_DATE,COUNTRY
the final output for usa should have shipping total amount of 35
Try using Max(ShippingTotal) instead of Sum so that you only get the shipping total once per order.
See this modification to your dbfiddle: https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=96827f2a82976bdf5f07d8d1831f391c
We are trying to write a query to find out how much of the order was fullfilled in the first invoice on that order. Look at ArTrnInvoice table for Invoice info and OrderDetail for orders info. Compare qty ordered on each sales order line to what was fulfilled on the first invoice on that order
We tried
select case when SalesOrderLine>0 THEN QtyInvoiced /MOrderQty *100 Else End as Order_fILL_RATE FROM OrderDetail a Left JOIN
OrderHeader b ON a.SalesOrder = b.SalesOrder
WHERE b.Order Status ='9'
Basically,Trying to Output :
How much of the order was fullfilled in the first invoice - Let' say I ordered 2000$ worth of items. And Business Org invoiced this to me in two parts. First 1800$ within 10 days and then another 200$ later (or didn't ship this at all). In this case fill rate = 90%
Given Conditions
We have sql server 2012. Trying to calculate Fill Order Rate Using Order Line Item.
We have 3 table which consist of OrderHeader Info,OrderDetail Info, Invoice info table .
Structure of these tables are Here in link:
OrderDetail Table
Structure is
OrderHeader Table DDL
Also OrderStatus='9' means Fulfilled Order.
Any help on it would be much appreciated ?
A newbie here. So please be kind :-)
I have 2 Tables namely Item & Item Entries.
Relation is: Item.No = ItemEntries.No.
In Item Entries Table I have Columns as Qty, Entry type, Purchase Amount, Sales Amount
I like to have a report which shows as below,
Item No. | Opening Quantity | Purchase Amount | Sales Amount
To calculate Opening Inventory I summed up the quantity field and the result is as expected. No problem in that. Now From that dataset I like to run a sub query which Calculates/Sum the Purchase amount for an Item that is a part of first dataset and similarly for Sales Amount.
Select(Item No.,Sum(IE.Quantity) As Quantity, Select(......Purchase Amount),Select(....Sales Amount)
I hope I was able to clear my doubts to you guys.
Something like :
SELECT ItemNo, sum(quantity), purchaseAmount, SalesAmount FROM Item i INNER JOIN ItemEntities ie on i.no = ie.no GROUP BY ItemNo, PurchaseAmount, SalesAmount;
I believe (if I understand what you want) that this is the solution to your problem
Select Item.No ,
Sum(IE.Quantity) As Quantity,
(Select(......Purchase Amount)) As ColumnName1 ,
(Select(....Sales Amount)) As ColumnName2
From your need to "sum the purchase amount for an item that is part of the first dataset and similarly for Sales Amount" I think what you're trying to achieve is one row for each item on the Item table with a sum for each of the Qty, Sales Amount and Purchase Amount. If so, then you can simply use a 'group by' clause which groups results together which have matching values for the columns specified.
SELECT I.no, SUM(IE.qty), SUM(IE.purchase_amount), SUM(IE.sales_amount)
FROM item I JOIN item_entries IE
ON I.no = IE.no
GROUP BY I.no;
See the group_by_clause for more details and some examples.
N.B. The join from the item tables isn't strictly required in this example, but if you're producing a report I suspect you might want to get things like a description - in which case you'll need to add those columns to the group by clause too.
You might need the sum of three columns from
ItemEntries table(Qty,PurchaseAmount,SalesAmount) for each Item.No
Select A.No,
Sum(B.Qty),
Sum(B.Purchaseamount),
Sum(B.Salesamount)
From Item A,
Itementries B
Where A.No = B.No
Group By A.No;
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