之间的日期间隔mysql今天不显示

时间:2019-01-06 07:47:20

标签: mysql 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
) AS pe ON p.idprd = pe.idprd 

我的结果

my result query

我的数据: enter image description here 日期'2019-01-06'未显示。如何显示我当前的日期

1 个答案:

答案 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;

查询结果SQL Query result snapshot