A
AR
I am trying to create a query containing specific information. Let me
explain...
I have the following tables:
Checkout Table contains the following fields:
CheckoutID
CheckoutDate
ClearanceCost
PaymentMethodID
OperatorID
PaymentMethod table contains the following fields:
PaymentMethodID
PaymentMethod
ClearanceCharge
ProductSale table contains the following fields:
ProductSaleID
UnitCost
CheckoutID
Assume the PaymentMethod table contains the following data:
PaymentMethodID PaymentMethod ClearanceCharge
1 Cash 0
2 Maestro Dom 0.565
3 Electron 0.35
4 Solo 0.345
5 Visa Delta 0.37
6 Mastercard 0.195
7 Visa 0.195
8 Amex 0.266
I want to calculate sum(ProductSale.UnitCost) where PaymentMethod is NOT
equal to Cash or Amex. I have mocked this up and it seems to work:
SELECT Checkout.CheckoutDate, Sum(ProductSale.UnitCost) AS ValueOfSales,
Count(*) AS NumberOfSales, Sum(Checkout.ClearanceCost) AS StreamlineCost
FROM Operator INNER JOIN (Checkout INNER JOIN ProductSale ON
Checkout.CheckoutID = ProductSale.CheckoutID) ON Operator.OperatorID =
Checkout.OperatorID
WHERE (((Checkout.PaymentMethodID)=2 Or (Checkout.PaymentMethodID)=3 Or
(Checkout.PaymentMethodID)=4 Or (Checkout.PaymentMethodID)=5 Or
(Checkout.PaymentMethodID)=6 Or (Checkout.PaymentMethodID)=7))
GROUP BY Checkout.CheckoutDate ORDER BY Checkout.CheckoutDate DESC;
I also want to calculate sum(ProductSale.UnitCost) where PaymentMethod=Amex.
Again, I have mocked this up and it seems to work:
SELECT Checkout.CheckoutDate, Sum(ProductSale.UnitCost) AS ValueOfSales,
Count(*) AS NumberOfSales, Sum(Checkout.ClearanceCost) AS AmexCost
FROM Operator INNER JOIN (Checkout INNER JOIN ProductSale ON
Checkout.CheckoutID = ProductSale.CheckoutID) ON Operator.OperatorID =
Checkout.OperatorID
WHERE (((Checkout.PaymentMethodID)=8))
GROUP BY Checkout.CheckoutDate
ORDER BY Checkout.CheckoutDate DESC;
These queries only return results where the ValueOfSales and NumberOfSales
is not zero... i would like them to return results for each day even if the
result is zero...
Also, I want the results from both queries as one result set i.e. I want the
results to look like:
Checkoutdate ValueOfSales NumberOfSales StreamlineCost AmexCost
2008.01.27 200.00 5
14.95 0.00
2008.01.28 235.64 7
15.98 1.45
....
I want two extra columns to be displayed ... even though their values might
be zero for a particular day.
Any help appreciated...
Thanks
explain...
I have the following tables:
Checkout Table contains the following fields:
CheckoutID
CheckoutDate
ClearanceCost
PaymentMethodID
OperatorID
PaymentMethod table contains the following fields:
PaymentMethodID
PaymentMethod
ClearanceCharge
ProductSale table contains the following fields:
ProductSaleID
UnitCost
CheckoutID
Assume the PaymentMethod table contains the following data:
PaymentMethodID PaymentMethod ClearanceCharge
1 Cash 0
2 Maestro Dom 0.565
3 Electron 0.35
4 Solo 0.345
5 Visa Delta 0.37
6 Mastercard 0.195
7 Visa 0.195
8 Amex 0.266
I want to calculate sum(ProductSale.UnitCost) where PaymentMethod is NOT
equal to Cash or Amex. I have mocked this up and it seems to work:
SELECT Checkout.CheckoutDate, Sum(ProductSale.UnitCost) AS ValueOfSales,
Count(*) AS NumberOfSales, Sum(Checkout.ClearanceCost) AS StreamlineCost
FROM Operator INNER JOIN (Checkout INNER JOIN ProductSale ON
Checkout.CheckoutID = ProductSale.CheckoutID) ON Operator.OperatorID =
Checkout.OperatorID
WHERE (((Checkout.PaymentMethodID)=2 Or (Checkout.PaymentMethodID)=3 Or
(Checkout.PaymentMethodID)=4 Or (Checkout.PaymentMethodID)=5 Or
(Checkout.PaymentMethodID)=6 Or (Checkout.PaymentMethodID)=7))
GROUP BY Checkout.CheckoutDate ORDER BY Checkout.CheckoutDate DESC;
I also want to calculate sum(ProductSale.UnitCost) where PaymentMethod=Amex.
Again, I have mocked this up and it seems to work:
SELECT Checkout.CheckoutDate, Sum(ProductSale.UnitCost) AS ValueOfSales,
Count(*) AS NumberOfSales, Sum(Checkout.ClearanceCost) AS AmexCost
FROM Operator INNER JOIN (Checkout INNER JOIN ProductSale ON
Checkout.CheckoutID = ProductSale.CheckoutID) ON Operator.OperatorID =
Checkout.OperatorID
WHERE (((Checkout.PaymentMethodID)=8))
GROUP BY Checkout.CheckoutDate
ORDER BY Checkout.CheckoutDate DESC;
These queries only return results where the ValueOfSales and NumberOfSales
is not zero... i would like them to return results for each day even if the
result is zero...
Also, I want the results from both queries as one result set i.e. I want the
results to look like:
Checkoutdate ValueOfSales NumberOfSales StreamlineCost AmexCost
2008.01.27 200.00 5
14.95 0.00
2008.01.28 235.64 7
15.98 1.45
....
I want two extra columns to be displayed ... even though their values might
be zero for a particular day.
Any help appreciated...
Thanks