我在表上的查询需要以下条件:
表:
user_id || amount || date
1 || 10 || 2019-04-01
1 || 25 || 2019-04-02
3 || 25 || 2019-04-04
1 || 25 || 2019-04-03
预期结果:获取user_id,日期,日期数量,月份数量(将user_id的所有日期金额总计为月份)
输入参数:user_id,月份的开始日期,月份的结束日期.
例如:user_id = 1,日期= 2019-04-02,开始日期= of-04–04-2019,结束日期= ofmonth = 2019-04-30
user_id || amount_of_date || date || amount_of_month
1 || 25 || 2019-04-02 || 60
最佳答案
您可以在下面尝试-
原文链接:https://www.f2er.com/mysql/531948.htmlselect user_id,max(case when date=@inputdate then amount end) as amount_of_Date,min(case when date=@inputdate then date end) as date,sum(amount) as amount_of_month
from tablename
where user_id=1 and date between '2019-04-01' and '2019-04-30'
group by user_id