码迷,mamicode.com
首页 > 数据库 > 详细

sql奇特的语句

时间:2018-03-28 14:14:56      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:blog   _for   苹果   一个   from   rom   date   count   代码   

1,一个表先将01,02,03类型编码转换文字,在做统计

技术分享图片

select CASE  IMPLEMENT_PROPETY
  WHEN 01 then 法定机关
   WHEN 02 then 授权组织
   WHEN 03 then 受委托组织
   ELSE 其他 END MMMMMM from test.pre_service

 

最终sql结果如下

SELECT temp.MMMMMM WW,COUNT(*) as Total from
 (select CASE  IMPLEMENT_PROPETY
  WHEN 01 then 法定机关
   WHEN 02 then 授权组织
   WHEN 03 then 受委托组织
   ELSE 其他 END MMMMMM
  from test.pre_service ) temp  group by temp.MMMMMM
//代码原型
select
temp.type as type, count(type) as Total from (select case 字段 WHEN 1 then 苹果 WHEN 2 then 香蕉 WHEN 3 then 西瓜 end as type from table ) temp where type is not null group by temp.type

 

 技术分享图片

2.

//1
 ---select IMPLEMENT_PROPETY , COUNT(*) Num from test.pre_service  GROUP BY IMPLEMENT_PROPETY


-- SELECT  dept_name ,COUNT(*) AAAA from test.pre_service_snapshot GROUP BY dept_name

-- SELECT dept_name, INFO_TYPE , COUNT(*) Num from test.pre_service_snapshot GROUP BY dept_name,INFO_TYPE

-- SELECT dept_name,SERVICE_TYPE ,COUNT(*) Num from test.pre_service_snapshot where INFO_TYPE=即办件 group by  dept_name,SERVICE_TYPE

-- select  DEPT_NAME ,COUNT(*) numBer from test.pre_service GROUP BY DEPT_NAME

--  select IMPLEMENT_PROPETY , COUNT(*) Num from test.pre_service  GROUP BY IMPLEMENT_PROPETY


-- select IMPLEMENT_PROPETY , COUNT(*) Num from test.pre_service  GROUP BY IMPLEMENT_PROPETY

-- select DATE_FORMAT(PROMISEE_TIME,%Y-%m) date ,count(projid) num ,HANDLESTATE from test.pre_apasinfo 
--  group by DATE_FORMAT(PROMISEE_TIME,%Y-%m),HANDLESTATE


-- -- select   hander_deptname , COUNT(*)  Accept_Number  FROM  test.pre_transact GROUP BY hander_deptname
-- 
-- select DATE_FORMAT(TRANSACT_TIME,%Y-%m) date ,count(projid) num ,hander_deptname from test.pre_transact 
--  group by DATE_FORMAT(TRANSACT_TIME,%Y-%m),hander_deptname

---SELECT SUM(*) from pre_serv

--  select transact_result  hander_deptname , COUNT(*)  Accept_Number ,hander_deptname FROM  test.pre_transact GROUP BY transact_result

-- select transact_result  transact_result , COUNT(*)  hander_Number  FROM  test.pre_transact GROUP BY transact_result
-- select OBJECT_NAME  name_institution , COUNT(*)  Complain_Number FROM test.pre_complain  GROUP BY OBJECT_NAME

---select   hander_deptname , COUNT(*)  Accept_Number  FROM  test.pre_transact GROUP BY hander_deptname

 

sql奇特的语句

标签:blog   _for   苹果   一个   from   rom   date   count   代码   

原文地址:https://www.cnblogs.com/kaiwen1/p/8662913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!