I have problem an now this is more than 2days and I can't find any answer. can you help me out guys. to solve my problem.
I use Server version: 10.4.6-MariaDB
Question: How to get the all records from the previous week by using the subquery ?
So now i have already have query getting the current record and previous week however the previous week getting wrong result the 4th column result from week today previous week..
This is my query:
SELECT market,storeid,CONCAT(FORMAT(sum(ns), 0)) as NS, (SELECT sum(ns) as nslw FROM cron_db.sales_report_export_1 WHERE txndate = CURDATE() - INTERVAL 7 DAY) FROM cron_db.sales_report_export_1 as sales_report1 LEFT JOIN (SELECT store_code,market FROM cron_db.store_master) sm ON sales_report1.storeid = sm.store_code WHERE market = "EDM" AND week = (SELECT DISTINCT(week) FROM cron_db.sales_report_export_1 WHERE txndate = SUBDATE(CURDATE(),2)) AND period = (SELECT DISTINCT(period) FROM cron_db.sales_report_export_1 WHERE txndate = SUBDATE(CURDATE(),2)) GROUP BY storeid
And the result:
Expect output must be: