我抛砖 select case when G1.cnt > G2.cnt then 'col_AAA' else 'col_BBB' end from (select count(t1.*) cnt from table_name t1 where t1.col_AAA <> null) G1, (select count(t2.*) cnt from table_name t2 where t2.col_BBB <> null) G2
补个别名 select case when G1.cnt > G2.cnt then 'col_AAA' col_name else 'col_BBB' col_name end from (select count(t1.*) cnt from table_name t1 where t1.col_AAA <> null) G1, (select count(t2.*) cnt from table_name t2 where t2.col_BBB <> null) G2
表有些字段,有些什么记录,sql结果是什么,举例说明
select (case kip>kip1 then a else b) from ( select a,b,sum(kip) kip,sum(kip1) kip from (select a,b,count(*)kip,0 kip1 from table where a is not null UNION all select a,b,0 kip, count(*) kip1from table where b is not null ) group a )
SELECT CASE WHEN (Q.COUNT1 - Q.COUNT2) > 0 THEN 'col1 有效' ELSE 'col2 有效' END RESULT FROM (SELECT COUNT(CASE WHEN T.COL1 IS NOT NULL THEN 1 ELSE 0 END) COUNT1, COUNT(CASE WHEN T.COL2 IS NOT NULL THEN 1 ELSE 0 END) COUNT2 FROM TAB1 T) Q
把函数修改了一下! SELECT CASE WHEN (Q.COUNT1 - Q.COUNT2) > 0 THEN 'col1 有效' ELSE 'col2 有效' END RESULT FROM (SELECT SUM(CASE WHEN T.COL1 IS NOT NULL THEN 1 ELSE 0 END) COUNT1, SUM(CASE WHEN T.COL2 IS NOT NULL THEN 1 ELSE 0 END) COUNT2 FROM TAB1 T) Q
select case when num1>num2 then 'col1' else 'col2' end from (select sum(decode(col1, null, 0, 1)) num1, sum(decode(col2, null, 0, 1)) num2 from table1);
已解决select (case when count(A_NO)>count(B_NO) then A_NO else B_NO end) as t_NO from t1 group by A_NO,B_NO
select case
when G1.cnt > G2.cnt then
'col_AAA'
else
'col_BBB'
end
from (select count(t1.*) cnt from table_name t1 where t1.col_AAA <> null) G1,
(select count(t2.*) cnt from table_name t2 where t2.col_BBB <> null) G2
select case
when G1.cnt > G2.cnt then
'col_AAA' col_name
else
'col_BBB' col_name
end
from (select count(t1.*) cnt from table_name t1 where t1.col_AAA <> null) G1,
(select count(t2.*) cnt from table_name t2 where t2.col_BBB <> null) G2
select a,b,sum(kip) kip,sum(kip1) kip from
(select a,b,count(*)kip,0 kip1 from table where a is not null
UNION all
select a,b,0 kip, count(*) kip1from table where b is not null
)
group a )
WHEN (Q.COUNT1 - Q.COUNT2) > 0 THEN
'col1 有效'
ELSE
'col2 有效'
END RESULT
FROM (SELECT COUNT(CASE
WHEN T.COL1 IS NOT NULL THEN
1
ELSE
0
END) COUNT1,
COUNT(CASE
WHEN T.COL2 IS NOT NULL THEN
1
ELSE
0
END) COUNT2
FROM TAB1 T) Q
SELECT CASE
WHEN (Q.COUNT1 - Q.COUNT2) > 0 THEN
'col1 有效'
ELSE
'col2 有效'
END RESULT
FROM (SELECT SUM(CASE
WHEN T.COL1 IS NOT NULL THEN
1
ELSE
0
END) COUNT1,
SUM(CASE
WHEN T.COL2 IS NOT NULL THEN
1
ELSE
0
END) COUNT2
FROM TAB1 T) Q
select case when num1>num2 then 'col1' else 'col2' end from (select sum(decode(col1, null, 0, 1)) num1, sum(decode(col2, null, 0, 1)) num2 from table1);
(case when count(A_NO)>count(B_NO) then A_NO else B_NO end) as t_NO
from t1 group by A_NO,B_NO