我的查询:
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
我的结果
答案 0 :(得分:0)
GROUP BY缺少列-这将阻止您甚至成功执行SQL语句。但是在调整SQL语句后,结果将包含正确的数据集。
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;