TT在努力 2022-11-14 14:17 采纳率: 82.4%
浏览 32
已结题

concat了好大一串

select count(distinct device_id) cnt,
case when day(event_date) between 01 and 09 then concat(year(event_date),'年',mouth(event_date),'月','上旬')
when day(event_date) between 10 and 19 then concat(year(event_date),'年',mouth(event_date),'月','中旬')
when day(event_date)>20then concat(year(event_date),'年',mouth(event_date),'月','下旬') end dt_range
from question_practice_detail
group by dt_range
order by mouth(event_date) desc,cnt desc

这个是我的bug代码,我用时间函数然后链接
select
(
concat(
concat(substr(event_date,1,4),'年'),
concat(substr(event_date,6,2),'月'),
(case
when day(event_date) between 1 and 9 then '上旬'
when day(event_date) between 10 and 19 then '中旬'
when day(event_date) >=20 then '下旬'
end))
)as dt_range,
count(distinct device_id) as cnt
from question_practice_detail
group by dt_range
order by substr(dt_range,6,2) desc, cnt desc
这是答案,用substri提取字符串
但我觉得用时间提取函数也ok吖。

  • 写回答

3条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-11-14 14:33
    关注

    你这个没有数据,也没有题目什么的,也不知道你数据是什么样啊,单看sql也看不出什么结果,如果你试一下查询结果一样那就可能是题目局限性或者数据局限性,只让使用它答案的sql吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月3日
  • 已采纳回答 11月25日
  • 创建了问题 11月14日

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了