Php 如何按不同日期分组,并在分组日期对每个数据求和
我正在做广告跟踪面板 我的数据库中有3个表 1-活动Php 如何按不同日期分组,并在分组日期对每个数据求和,php,mysql,sql,Php,Mysql,Sql,我正在做广告跟踪面板 我的数据库中有3个表 1-活动 id orderID name startDate endDate goal type status unitPrice total lineItem_id id lineItemOrderID lineItemName lineItemStartDate lineItemEndDate lineItemStatus lineItemType lineItemGoal statics_id lineItem_id inventoryID
id
orderID
name
startDate
endDate
goal
type
status
unitPrice
total
lineItem_id
id
lineItemOrderID
lineItemName
lineItemStartDate
lineItemEndDate
lineItemStatus
lineItemType
lineItemGoal
statics_id
lineItem_id
inventoryID
inventoryName
impression
click
staticsDate
2行项目
id
orderID
name
startDate
endDate
goal
type
status
unitPrice
total
lineItem_id
id
lineItemOrderID
lineItemName
lineItemStartDate
lineItemEndDate
lineItemStatus
lineItemType
lineItemGoal
statics_id
lineItem_id
inventoryID
inventoryName
impression
click
staticsDate
3-行项目静态
id
orderID
name
startDate
endDate
goal
type
status
unitPrice
total
lineItem_id
id
lineItemOrderID
lineItemName
lineItemStartDate
lineItemEndDate
lineItemStatus
lineItemType
lineItemGoal
statics_id
lineItem_id
inventoryID
inventoryName
impression
click
staticsDate
我的表格示例:
我喜欢这个结果:
如何按不同日期分组,并在分组日期对每个数据求和
我的示例代码:(它不是真的,值是假的)
尝试此操作-在嵌套查询中,使用
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)
您需要使用
groupby
重新转换派生表(日期、静态数据)