当前位置: 代码迷 >> Oracle开发 >> 新人求大神解释解释sql语句,该如何解决
  详细解决方案

新人求大神解释解释sql语句,该如何解决

热度:123   发布时间:2016-04-24 06:35:08.0
新人求大神解释解释sql语句
select t.*,( case when (select count(1) from t_xdt_usual_question_type t1 where  t1.PARENT_TAG=t.issue_TYPE )>0 then 'true' else 'false' end ) 
as isparent  from t_xdt_usual_question_type t where 1=1;


看不懂这个sql语句 请大神指教
------解决思路----------------------
select t.*,( case when (select count(1) from t_xdt_usual_question_type t1 where  t1.PARENT_TAG=t.issue_TYPE )>0 then 'true' else 'false' end ) 
as isparent  from t_xdt_usual_question_type t where 1=1;

case when 条件1 then 结果1 else 结果2 end的用法
当满足条件的时候,返回结果1,不满足返回结果2
------解决思路----------------------
select t.*,
       (case
         when (select count(1)
                 from t_xdt_usual_question_type t1
                where t1.PARENT_TAG = t.issue_TYPE) > 0 then
          'true'
         else
          'false'
       end) as isparent
  from t_xdt_usual_question_type t
 where 1 = 1;

查询表t_xdt_usual_question_type 所有字段以及isparent字段 isparent字段显示有下面查询确定
如果查询select count(1)
                 from t_xdt_usual_question_type t1
                where t1.PARENT_TAG = t.issue_TYPE) > 0 结果大于0   isparent字段显示为true 否则显示为false





  相关解决方案