我正在做广告跟踪小组。
我的数据库上有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
答案 0 :(得分:0)
试试这个 - 在嵌套查询中,使用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)