In MS Sql.
SELECT a.SellerID,
SUM(TransactionFee) as TransactionFees,
SUM(Quantity*a.PriceItem) as TransactionValue,
COUNT(*) as OrdersWithTransactionFees,
SUM(Quantity) as Qty,
(SELECT SUM(a.Quantity*a.PriceItem) as WholeMonthTransactionValue
from BuyProductDetails where SellerID = a.SellerID) as aa
FROM BuyProductDetails as a
WHERE MONTH(a.OrderDate)=3
AND YEAR(a.OrderDate)=2013
AND TransactionFee IS NOT NULL
GROUP BY a.SellerID
I have the above query... it can't seems to be able to run.
Basically, I have this table BuyProductDetails which stores all the orders from different Sellers.
Some orders will have TransactionFee.
Now, what I need is to calculate the total sales of these orders with TransactionFee, and the total sales for these sellers including those orders without TransactionFee.
The result set should have the following fields:
- SellerID
- Sum of Transaction fee
- Sum of total sales
- Number of Orders with Transaction fee
- Qty ordered
- Total sales for that seller
But when I run this sql, it returns the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Any help is much appreciated. Thank you.