撒花时刻到了...求各位牛牛解决..关于sql查询语句的问题
现在有两张表
另一张是
我现在想要的效果是..
下面这是我之前一个表的时候做的统计..
<select id="getReportListByTime" resultType="com.tmg.entity.recruitment.pojo.ReportList" parameterType="map" > select sum(STATUS = 'suitable') AS suiNum, sum(STATUS = 'unsuitable') AS unsuiNum, sum(DEAL_STATUS = 'Signed') AS signedNum, sum(DEAL_STATUS = 'Refused') AS refusNum, sum(DEAL_STATUS = 'Connected' OR DEAL_STATUS = 'Signed' OR DEAL_STATUS = 'Refused') AS connectNum, sum(DEAL_STATUS IS NOT NULL) AS reachedNum, CHOOSE_BY AS userName from RECRU_USER_REPOSITORY <trim prefix="WHERE" prefixOverrides="AND |OR "> <if test="start!=null and !start.equals('')"> and CHOOSE_TIME <![CDATA[>=]]> #{start,jdbcType=VARCHAR} </if> <if test="end!=null and !end.equals('')"> and CHOOSE_TIME <![CDATA[<=]]> #{end,jdbcType=VARCHAR} </if> and CHOOSE_BY IS NOT NULL </trim> group by CHOOSE_BY </select> </mapper>
SELECT T.LOGINNAME "loginName", SUM(CASE T.MARK WHEN '1' THEN 1 ELSE 0 END) "marked"
, SUM(CASE DEALSTALE WHEN 'suitable' THEN 1 ELSE 0 END) "suitable"
, SUM(CASE DEALSTALE WHEN 'unsuitable' THEN 1 ELSE 0 END) "unsuitable"
, SUM(CASE DEALSTALE WHEN 'Reached-out' THEN 1 ELSE 0 END) "Reached-out"
, SUM(CASE DEALSTALE WHEN 'Connected' THEN 1 ELSE 0 END) "Connected"
FROM
(SELECT LOGINNAME,DEALSTALE, '1' MARK FROM USERMARK
UNION ALL
SELECT LOGINNAME,DEALSTALE, '0' MARK FROM USERTRUSH) T GROUP BY T.LOGINNAME ORDER BY T.LOGINNAME;
这是Mysql的写法
SELECT
a.loginName,
sum(1) AS marked,
sum(if(a.dealstale='suitable',1,0)) AS suitable,
sum(if(b.dealstale='unsuitable',1,0)) AS unsuitable,
sum(if(a.dealstale='Reached-out',1,0)) AS "Reached-out",
sum(if(a.dealstale='connected',1,0)) AS connected
FROM
test.usermark a,
test.usertrush b
WHERE
a.id = b.id
GROUP BY
a.loginName
如果是oracle 就把if换成decode 就好了
如图
select t1.loginname ,t2.mark ,t1.suitable,t1.unsuitable,t1."reached-out",t1.connected from
(
select
loginname,
sum(case when dealstale = 'suitable' then 1 else 0 end ) as suitable ,
sum(case when dealstale = 'unsuitable' then 1 else 0 end ) as unsuitable,
sum(case when dealstale = 'reached-out' then 1 else 0 end ) as "reached-out",
sum(case when dealstale = 'connected' then 1 else 0 end ) as connected
from
(select * from usermark union select * from usertrush )
group by loginname order by 1
) t1,
(select loginname ,count(*) as mark from usermark group by (loginname ) order by loginname) t2
where t1.loginname = t2.loginname
- 等 最代码怎么获取牛币啊?
- 完 谁来告诉我最代码上线的时间,答对者给5牛币,先来先得
- 等 牛友们,大家好,你们做程序员多久了?现在还好吗?
- 完 在微信打开的页面里进行app下载
- 等 最代码2014年欢乐聚声会
- 完 mysql如何查询表数据并且对3个字段降序的SQL?
- 完 最代码牛币机制改革
- 完 成功的在bae上使用了自定义运行环境 jetty+nginx的组合,大家对jetty+nginx优化有哪些心得?
- 完 进来分享一下各位牛牛是如何加入最代码大家庭的?
- 等 为什么java BufferedImage类处理大图直接抛出内存溢出的异常?
- 等 最代码是否开发手机app客户端?
- 完 java程序员学习哪些java的技术?java有哪些框架?都能做哪方面的开发?
- 等 php格式网页文件怎么运行?
- 等 Java volatile值获取的问题
- 等 前端vue,拦截了登录后台后,返回的token,requests拦截token,但是发送请求的时候,就出现跨越异常
- 等 大专本科计算机科班怎么找到Java工作?
- 等 eclipse怎么把三个java swing游戏项目合成一个项目?
- 完 伙伴们,大家都有什么好的解压方式么,分享一下~
- 完 三四线城市,6、7k,运维工作,索然无味,想去辞职上培训,各位牛牛有什么建议嘛
- 等 jsp页面输入中文变成问号
- 等 JPA在线上运行一段时间后报错Caused by: java.lang.IncompatibleClassChangeError: null
- 等 PHP 这个规则用preg_match_all怎么写
- 等 大佬们,有没有知道Alfresco如何配置LDAP登录呢?
- 等 php的install目录是框架带的吗?