About 17,300,000 results
Open links in new tab
  1. mysql - Write an SQL Query to calculate total purchase amount

    Nov 29, 2019 · My current query gives me the product wise purchase amount for the customer. What I need is the total purchase amount. SELECT c.CustomerID,o.OrderID,(ord.Quantity*p.Price) as Total_Amount from Customers c inner join Orders o inner join Products p inner join OrderDetails ord on c.CustomerID = o.CustomerID and o.OrderID = ord.OrderID and ord ...

  2. SQL: Find the total purchase amount for all orders - w3resource

    Feb 11, 2025 · From the following table, write a SQL query to calculate total purchase amount of all orders. Return total purchase amount. Sample table: orders. Sample Solution: -- This query calculates the sum of the 'purch_amt' column. -- Specifies the table from which to retrieve the data (in this case, 'orders'). Output of the Query: Code Explanation:

  3. sql - Select first purchase for each customer - Stack Overflow

    SELECT H.transaction_no, H.customer_id, H.operator_id, H.purchase_date FROM Sales_Transactions_Header H INNER JOIN (SELECT customer_id, MIN(purchase_date) As first_occurence FROM Sales_Transactions_Header GROUP BY customer_id) X ON H.customer_id = X.customer_id AND H.purchase_date = X.first_occurence

  4. sql - MySQL - Select all customers and each customer's total …

    Mar 2, 2013 · For each customer, I want to return: id, name, total_orders, total_value. Customers: Orders: How do I select a result like: a.Name, COUNT(b.Customer) totalOrders, SUM(b.value) total_value. LEFT JOIN Orders b. ON a.ID = b.Customer. a.Name. OR. a.Name, COUNT(b.Customer) totalOrders, COALESCE(SUM(b.value), 0) total_value. LEFT JOIN …

  5. SQL: Customer details and purchases over a certain amount - w3resource

    Feb 11, 2025 · Return customer id and maximum purchase amount. Sample table: orders. Sample Solution: -- This query retrieves the maximum 'purch_amt' value for each 'customer_id' from the 'orders' table. -- It only includes rows where the 'customer_id' is between 3002 and 3007.

  6. join - SQL queries to only show most recent purchase records for ...

    Dec 1, 2015 · So to only show the most recent, you must limit the columns displayed. Try something like: SELECT [Food purchase data].[Food item ID], max(Invoices.[Invoice Date]) AS MostRecentInvoiceDate FROM Invoices INNER JOIN ([Food items] ON [Food items].ID = [Food purchase data].[Food item ID]) GROUP BY [Food purchase data].[Food item ID]

  7. Help needed with a SQL statement for a Quick Report

    Dec 1, 2021 · I want to show the total amount of a Purchase Order including charges (when a charge or multiple charges are applied on an order) and excluding tax. I created the statement below, but did not get the desired result. The statement is working fine, except the bold part.

  8. SQL: Higher purchase amount by the customer within a list

    Sep 10, 2012 · From the following table, write a SQL query to find the maximum order (purchase) amount based on the combination of each customer and order date. Filter the rows for maximum order (purchase) amount is either 2000, 3000, 5760, 6000. Return customer id, order date and maximum purchase amount. Sample table: orders

  9. Mastering SQL Queries for PO Line Amount Management

    Jan 20, 2025 · SELECT PO_number, SUM(Line_Amount) AS Total_PO_Line_Amount FROM Purchase_Order GROUP BY PO_number; This query sums up line amounts for each purchase order number, providing a comprehensive view of total expenditure.

  10. mysql - Query to find the customer with highest amount of total ...

    Sep 17, 2016 · The query up one level uses the inner query results and adds on the max summed total of purchases. The outer-most query joins the CUSTOMER_T table with the inner results to get the customer Name and total order amount for all customers that match the MAXAMT value.

Refresh