my query:
SELECT p.idprd, p.nmprd, pe.idprd, pe.stockjual, pe.stockkeluar, pe.tothrgjual, pe.tgljual FROM tbproduk AS p INNER JOIN ( SELECT idprd, Sum(stockjual) AS 'stockjual', Sum(stockkeluar) AS 'stockkeluar', Sum(tothrgajual) AS 'tothrgjual', tgljual FROM tbpenjualan WHERE '2019-01-06' >= '2019-01-06' - INTERVAL 7 day AND '2019-01-06' < '2019-01-06' + INTERVAL 7 day GROUP BY idprd ) AS pe ON p.idprd = pe.idprd
my result
my data: date ‘2019-01-06’ not showing. how to my currentdate to showing
Advertisement
Answer
GROUP BY has missing column – which would prevent you to even execute SQL statement successfully. But after adjusting SQL statement, results include correct sets of data.
SELECT p.idprd, p.nmprd, pe.idprd, pe.stockjual, pe.stockkeluar, pe.tothrgjual, pe.tgljual FROM tbproduk AS p INNER JOIN ( SELECT idprd, Sum(stockjual) AS 'stockjual', Sum(stockkeluar) AS 'stockkeluar', Sum(tothrgajual) AS 'tothrgjual', tgljual FROM tbpenjualan WHERE '2019-01-06' >= '2019-01-06' - INTERVAL 7 day AND '2019-01-06' < '2019-01-06' + INTERVAL 7 day GROUP BY idprd, tgljual ) AS pe ON p.idprd = pe.idprd ORDER BY pe.tgljual desc;