加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql-在一个查询的同一字段中为一个日期和一段时间选择时间戳

发布时间:2021-02-25 17:21:49 所属栏目:MySql教程 来源:网络整理
导读:我在表上的查询需要以下条件: 表: user_id || amount || date1 || 10 || 2019-04-011 || 25 || 2019-04-023 || 25 || 2019-04-041 || 25 || 2019-04-03 预期结果:获取user_id,日期,日期数量,月份数量(将user_id的所有日期金额总计为月份) 输入参数:user_

我在表上的查询需要以下条件:

表:

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
最佳答案 您可以在下面尝试-

select 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

(编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读