mysql
LeeShaoQing
这个作者很懒,什么都没留下…
展开
-
MySQL删除重复数据
mysql删除重复数据只保留一条。原创 2022-07-11 16:52:19 · 1033 阅读 · 0 评论 -
MYSQL查询当前月每天的数据,没有设置0
SELECT date as 日期, IFNULL(tab.num, 0) as 数量 FROM (SELECT @cdate := date_add( @cdate, INTERVAL - 1 DAY ) as dateFROM ( SELECT @cdate := date_add(CURDATE(), INTERVAL + 1 DAY ) FROM ccs_work_order )d1 WHERE YEAR(@cdate)=YEAR(CURDATE()) AND MONTH(@cd原创 2021-09-24 20:04:22 · 569 阅读 · 0 评论 -
MySQL统计过去12个月的数据。
当前月份往前推12个月份的数据信息。select DATE_FORMAT(cwo.create_time, '%Y-%m') as createDate, count(case when (cwo.process_method_code = 1 or cwo.process_method_code = 2) then 1 END) as hdCount,count(case when cwo.process_method_code = 3 then 1 END) as siteCountfrom c原创 2021-07-12 15:03:43 · 733 阅读 · 0 评论 -
MySQL递归查询所有下级节点
MySQL递归查询所有下级节点。先上SQL后来讲解其中的含义。select id from ( select t1.id,t1.inviteId, if(find_in_set(inviteId, @pids) > 0, @pids := concat(@pids, ',', id), 0) as isbig from ( select id,inviteId from cu原创 2021-07-12 10:46:51 · 3295 阅读 · 0 评论 -
MySQL如何一行数据统计多个COUNT
SELECTcount(CASE WHEN 字段 = ‘值’ THEN 1 end) as ‘A’,count(CASE WHEN 字段 = ‘值’ THEN 1 end) ‘B’,count(CASE WHEN 字段 = ‘值’ THEN 1 end) ‘C’FROM tableWHERE 条件原创 2021-07-08 15:59:55 · 1506 阅读 · 0 评论 -
MySQL如何自定义排序。
需求:根据指定字段将里面不同的值按照我定义的方式排序。select * from table as cwoorder by (case when cwo.work_order_status_code = 1 then 0when cwo.work_order_status_code = 2 then 1when cwo.work_order_status_code = 3 then 2when cwo.work_order_status_code = 4 then 3when cwo.work_原创 2021-06-24 14:44:31 · 108 阅读 · 0 评论 -
MySQL统计当前月每一天的数量
MySQL查询这个月的每一天数量select date_format(create_time, '%Y-%m-%d') as create_time, count(*) as count from table where DATE_FORMAT(create_time,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m') and cond = '123456'GROUP BY create_time原创 2021-04-07 11:04:23 · 1092 阅读 · 0 评论 -
MySQL获取上个月每一天的数据统计
SQL查询上个月每一天的数量。SELECT date_format(create_time, '%Y-%m-%d') as create_time, count(*) as count FROM table WHEREdate_format(create_time, '%Y%m') = date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y%m')and cond = '123456'GROUP BY create_time...原创 2021-04-07 11:01:38 · 718 阅读 · 0 评论