我在显示报告时遇到一些困难,该报告可以将所有日期分组到一个月,但也总结了#34;花费"每月每天。
我的SQL查询创建了这个:(检索所有日期)
Date Name Spend
2018-01-03 00:00:00.000000 xxxxxxxxx 34.699999999999996
2018-01-03 00:00:00.000000 xxxxxxxxx 31.89999999999999
2018-01-03 00:00:00.000000 xxxxxxxxx 29.49
2018-01-03 00:00:00.000000 xxxxxxxxx 52.15
2018-01-03 00:00:00.000000 xxxxxxxxx 101.07000000000001
2018-01-03 00:00:00.000000 xxxxxxxxx 104.37999999999998
我想要的是:(检索一个月而不是几天)
Month Name Spend
2018-01 xxxxxxxxx 34.69999999999999(summed monthly)
2018-02 xxxxxxxxx 31.89999999999999(summed monthly)
2018-03 xxxxxxxxx 29.49(summed monthly)
2018-04 xxxxxxxxx 52.15(summed monthly)
2018-05 xxxxxxxxx 101.07000000000001(summed monthly)
2018-06 xxxxxxxxx 104.37999999999998(summed monthly)
这是我的SQL查询:
SELECT
"GregorianDate" as date_year,
"AccountName" as account_name,
sum("Spend") as spend
FROM bingads_redperformance.keyword_performance_report
WHERE
EXTRACT(YEAR FROM ("GregorianDate")) = 2018
GROUP BY date_year, account_name
LIMIT 1000
我尝试添加MONTH(date_year)但它没有用。我希望有人可以指导我朝正确的方向发展。
答案 0 :(得分:1)
这个怎么样(你应该按月分组):
SELECT
EXTRACT(MONTH FROM ("GregorianDate")) as date_month,
"AccountName" as account_name,
sum("Spend") as spend
FROM bingads_redperformance.keyword_performance_report
WHERE
EXTRACT(YEAR FROM ("GregorianDate")) = 2018
GROUP BY date_month, account_name
LIMIT 1000
答案 1 :(得分:1)
我用样本数据对此进行了测试。工作正常。
rstyle