sql奇特的语句

Posted kaiwen1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql奇特的语句相关的知识,希望对你有一定的参考价值。

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奇特的语句的主要内容,如果未能解决你的问题,请参考以下文章

Microsoft SQL Server 代码片段收集

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段

下单快发货慢:一个 JOIN SQL 引起 SqlClient 读取数据慢的奇特问题

动态SQL基础概念复习(Javaweb作业5)

Mybatis超强大的动态SQL大全

mybatis学习日志二