我正在做广告跟踪面板。

我的数据库中有3个表,

1-广告活动

id
orderID
name
startDate
endDate
goal
type
status
unitPrice
total


2行项目

lineItem_id
id
lineItemOrderID
lineItemName
lineItemStartDate
lineItemEndDate
lineItemStatus
lineItemType
lineItemGoal


3行项目静态

statics_id
lineItem_id
inventoryID
inventoryName
impression
click
staticsDate


我的表格示例:



我想要这个结果:



如何按不同日期分组并汇总分组日期上的每个数据

我的示例代码:(这不正确,值false)

SELECT inventoryNameGI, SUM(impressionGI), SUM(clickGI)
FROM
(
    SELECT DISTINCT inventoryName AS inventoryNameGI,
           MAX(impression) AS impressionGI,
           MAX(click) AS clickGI
    FROM   `line_items_statics`
    WHERE  `lineItemID` = '5'
    AND    staticsDate BETWEEN '2017-07-01 00:00:00'
                           AND '2017-07-03 23:59:59'
    GROUP BY `inventoryName`
) AS toplamTablo

最佳答案

尝试执行此操作-在嵌套查询中,使用CONVERT仅将DATETIME转换为DATE

SELECT INVENTORYID, SUM(IMPRESSION), SUM(CLICK), CONVERT(DATE,STATICSDATE)
FROM `line_items_statics`
WHERE `lineItemID` = '5'
  AND normalDate BETWEEN '2017-07-01' AND '2017-07-03'
GROUP BY INVENTORYID,
         CONVERT(DATE,STATICSDATE)

10-08 09:35