Hi seb, thanks, I am just trying to convert my oracle query into hibernate which requires many subquery,here is complete query
Code:
[b]SELECT
Restaurant_Name AS RestaurantName,
SUM( SumOfTotal) + SUM(Inner_Discount) - SUM(giftpaid) AS TotalPrice,
SUM( SumOfTotal) + SUM(Inner_Discount) - SUM(giftpaid) AS TotalPrice1,
SUM(SumOfSubTotal) - SUM(giftpaid) AS netsale,
SUM( SumOfTax) AS SumTax,
SUM(SumOfTotal) - SUM(giftpaid) AS adjustedGross,
Close_Date AS CloseDate,
SUM(Royalty) AS TotRoyalty,
SUM(National_Ad) AS NationalAd,
SUM(Co_Op) AS CoOp,
Restaurant_ID,
SUM(Inner_Discount) AS disc,
SUM(SoldPrice) AS Negative_coupon,
COUNT(check1) AS checkNO,
SUM(coupons) AS Positive_coupon
FROM
(
SELECT
LOCATION.RestaurantName AS Restaurant_Name,
SUM(POSTABLES.SubTotal) AS SumOfSubTotal,
SUM(POSTABLES.Tax) AS SumOfTax,
SUM(POSTABLES.subTotal) AS SumOfTotal,
COUNT(POSTABLES.CheckNUM) AS check1,
POSTABLES.CloseDate AS Close_Date,
POSTABLES.RestaurantID AS Restaurant_ID,
SUM((SELECT SUM(POSTRANS.DISCOUNT) FROM POSTRANS, POSTABLES WHERE POSTRANS.Checknum=POSTABLES.Checknum))Inner_Discount,
SUM((SELECT SUM(POSTRANS.Sold) FROM POSTRANS WHERE POSTRANS.Checknum=POSTABLES.Checknum AND POSTRANS.SubGroup = 55 GROUP BY Checknum)) coupons,
SUM((SELECT SUM(POSTRANS.Sold) FROM POSTRANS WHERE POSTRANS.Checknum=POSTABLES.Checknum AND POSTRANS.SubGroup = 86 GROUP BY Checknum)) SoldPrice,
SUM((SELECT NVL(SUM(POSTRANS.Sold),0) FROM POSTRANS WHERE POSTRANS.Checknum=POSTABLES.Checknum AND POSTRANS.ItemName IN ('Gift Certificate') OR POSTRANS.SubGroup = 79 OR POSTRANS.SubGroup = 84)) giftpaid
FROM
LOCATION, POSTABLES
WHERE LOCATION.RestaurantID = POSTABLES.RestaurantID
GROUP BY LOCATION.RestaurantName, POSTABLES.CloseDate, POSTABLES.RestaurantID
HAVING ((POSTABLES.CloseDate BETWEEN TO_DATE('08/03/2005','MM/DD/YYYY') AND TO_DATE('08/04/2005','MM/DD/YYYY')) AND POSTABLES.RestaurantID='1007')
)
GROUP BY Restaurant_Name, Close_Date,Restaurant_ID [/b]
sorry for inconvenience in reading query :)