有两个sql语句
select count(tbxz) 投诉 
from tsby where tbxz =0select count(tbxz) 表扬 
from tsby where tbxz =1 怎么样把这两个结果集横向合并在一个表里面,形成如:投诉  表扬
12    15

解决方案 »

  1.   

    select a.表扬, b.投宿 (select count(tbxz) 投诉 
    from tsby where tbxz =0) a,(select count(tbxz) 表扬 
    from tsby where tbxz =1 ) b
      

  2.   

    正确答案是
    select a.表扬,b.投诉 from (select count(tbxz) 表扬 from tsby where tbxz =0) a,
               (select count(tbxz) 投诉 from tsby where tbxz =1 ) b
      

  3.   

    select count(tbxz) 投诉,(select count(tbxz) from tsby where tbxz =0) 表扬  from tsby where tbxz =0
      

  4.   


    select sum(decode(tbxz,1,1,0)) "投诉", sum(decode(tbxz,0,1,0)) "表扬" from tsby
      

  5.   

    select sum(decode(tbxz,1,1,0)) "投诉", sum(decode(tbxz,0,1,0)) "表扬" from tsby
    厉害;
    decode的语法:
    DECODE(value,if1,then1,if2,then2,if3,then3,...,else),表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else
      

  6.   


    select sum(decode(tbxz, '投诉', 1, 0)) "投诉",
    sum(decode(tbxz, '表扬', 1, 0)) "表扬"
    from tsby
      

  7.   

    duanzilin(寻)  的方法很好
      

  8.   

    select sum(decode(tbxz,1,1,0)) "投诉", sum(decode(tbxz,0,1,0)) "表扬" from tsby