Hello!
I have a problem which I can't figure out the solution for. I am a parttime coder with very limited capabilities. I have developed a report which is being generated from 3 tables. Problem is that all the tables have a field of RId (restaurant Id) and i want to process with where clause of RID=4, I have inserted where clause after "FROM DailyReport " but it gives error.
can someone pls help me here. Below is the SQL:
SELECT
DailyReport.DRId,
DailyReport.ReportDate,
DailyReport.`Total Covers`,
DailyReport.`Total Sales`,
(select sum(t2.Amount) from FoodCost t2 where t2.InvoiceDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.InvoiceDate <= DailyReport.ReportDate ) as FoodCost_MTD,
(select sum(t2.LaborCost) from Labor t2 where t2.ReportingDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportingDate <= DailyReport.ReportDate ) as LaborCost_MTD,
(select sum(t2.Royalty) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Royalty_MTD,
(select sum(t2.Wastage) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Wastage_MTD,
(select sum(t2.`Total Sales`) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as TotalSales_MTD,
(select sum(t2.MaintCosts) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as MaintCosts_MTD,
(select sum(t2.Rent) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Rent_MTD,
(select sum(t2.`Total Covers`) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as TotalCovers_MTD,
DailyReport.GST,
DailyReport.RId,
DailyReport.PST,
DailyReport.Profit,
DailyReport.`YTD Rise`,
DailyReport.isEmailSent,
DailyReport.FromEmail,
DailyReport.FromName,
DailyReport.EmailAddresses,
DailyReport.CC,
DailyReport.Remarks,
DailyReport.CheckLists,
DailyReport.`HalfHour Reports`
FROM DailyReport
Left Join FoodCost ON DailyReport.ReportDate = FoodCost.InvoiceDate
Left Join Labor ON DailyReport.ReportDate = Labor.ReportingDate
Order By DailyReport.ReportDate DESC
I have a problem which I can't figure out the solution for. I am a parttime coder with very limited capabilities. I have developed a report which is being generated from 3 tables. Problem is that all the tables have a field of RId (restaurant Id) and i want to process with where clause of RID=4, I have inserted where clause after "FROM DailyReport " but it gives error.
can someone pls help me here. Below is the SQL:
SELECT
DailyReport.DRId,
DailyReport.ReportDate,
DailyReport.`Total Covers`,
DailyReport.`Total Sales`,
(select sum(t2.Amount) from FoodCost t2 where t2.InvoiceDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.InvoiceDate <= DailyReport.ReportDate ) as FoodCost_MTD,
(select sum(t2.LaborCost) from Labor t2 where t2.ReportingDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportingDate <= DailyReport.ReportDate ) as LaborCost_MTD,
(select sum(t2.Royalty) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Royalty_MTD,
(select sum(t2.Wastage) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Wastage_MTD,
(select sum(t2.`Total Sales`) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as TotalSales_MTD,
(select sum(t2.MaintCosts) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as MaintCosts_MTD,
(select sum(t2.Rent) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as Rent_MTD,
(select sum(t2.`Total Covers`) from DailyReport t2 where t2.ReportDate >= date_sub(DailyReport.ReportDate, interval day(DailyReport.ReportDate) - 1 day) and t2.ReportDate <= DailyReport.ReportDate ) as TotalCovers_MTD,
DailyReport.GST,
DailyReport.RId,
DailyReport.PST,
DailyReport.Profit,
DailyReport.`YTD Rise`,
DailyReport.isEmailSent,
DailyReport.FromEmail,
DailyReport.FromName,
DailyReport.EmailAddresses,
DailyReport.CC,
DailyReport.Remarks,
DailyReport.CheckLists,
DailyReport.`HalfHour Reports`
FROM DailyReport
Left Join FoodCost ON DailyReport.ReportDate = FoodCost.InvoiceDate
Left Join Labor ON DailyReport.ReportDate = Labor.ReportingDate
Order By DailyReport.ReportDate DESC