select 
 (select count(*) from t_bm) zrs,
 (select count(*) from t_bm where bm_xb ='男') nrs,
 (select count(*) from t_bm where bm_mz = '汉族') hrs 
from dual;

解决方案 »

  1.   

    最直接的办法:select Distinct A.zrs ,B.nrs,C.hrs From 
    (select count(*)  zrs from t_bm ) A,
    (select count(*)  nrs from t_bm Where bm_xb ='男') B,
    (select count(*)  hrs from t_bm where bm_mz = '汉族') C
      

  2.   

    SQL> select * from t_bm;BM BM_MZ
    -- ----------
    男 汉
    男 汉
    男 汉
    男 汉
    男 汉
    女 汉
    女 汉
    女 藏
    女 哈萨克
    女 哈萨克
    男 傣
    男 布依
    男 哈尼
    女 维吾尔已选择14行。SQL> select count(bm_mz) total,
                count(decode(bm_xb,'男',bm_xb,'')) male,
                count(decode(bm_mz,'汉',bm_mz,'')) han_nationality
         from   t_bm;     TOTAL       MALE HAN_NATIONALITY
    ---------- ---------- ---------------
            14          8               7
      

  3.   

    select count(1) zrs,
           sum(case when bm_xb = '男' then 1 else 0 end) nrs,
           sum(case when bm_mz = '汉' then 1 else 0 end) hrs
         from   t_bm;
      

  4.   

    select count(1) zrs,
           sum(decode(bm_xb,'男',1,0)) nrs,
           sum(decode(bm_mz,'汉',1,0)) hrs
         from   t_bm;
      

  5.   

    select count(*) as zrs,sum(decode(bm_xb,'男',1,0)) as nrs,sum(decode(bm_mz,'汉',1,0)) as hrs from t_bm;这就是oracle里对应于你sqlserver里的写法,而且对表t_bm只扫描了一次!
      

  6.   

    select count(*) as zrs,
           sum(decode(bm_xb,'男',1,0)) as nrs,
           sum(decode(bm_mz,'汉族',1,0)) as hrs
    from t_bm楼主散分。
      

  7.   

    就是像sbaz(万神渡劫) 这种做法!
      

  8.   

    select count(*) total,
           sum(decode(bm_xb,'男',1,0)) male,
           sum(decode(bm_mz,'汉',1,0)) han_nationality
    from t_bm;
      

  9.   

    select count(*) as zrs,
           sum(decode(bm_xb,'男',1,0)) as nrs,
           sum(decode(bm_mz,'汉族',1,0)) as hrs
    from t_bm
    的方法比嵌套的好多了。
      

  10.   

    select count(*) as zrs,
           sum(decode(bm_xb,'男',1,0)) as nrs,
           sum(decode(bm_mz,'汉族',1,0)) as hrs
    from t_bm
    正确,楼主散分呀。
      

  11.   

    select count(ROWID) as zrs,  -------效率会高一点
           sum(decode(bm_xb,'男',1,0)) as nrs,
           sum(decode(bm_mz,'汉族',1,0)) as hrs
    from t_bm
    where rownum=1    -------执行效率可能会好一点(如果需求的返行是1行的情况下)
      

  12.   

    select count(*) as zrs,
           sum(decode(bm_xb,'男',1,0)) as nrs,
           sum(decode(bm_mz,'汉族',1,0)) as hrs
    from t_bm
    正确
      

  13.   

    不好意思,好久以前的帖子,由于当时服务器不好使,没能及时结贴。
    另说明:我的题目中关于sql server 中的写法是错误的,请浏览的朋友不要效仿。
    sql 中应该用 case 语句。