select count(*) as index_count,model from C_ACCESS_LOG group by model,PAGEID 
having model in (1503,2090,1511,1520,1529) and PAGEID in (1505,1479,1462,1481,1569)
得出的结果是
index_count  model 
8            1520但我想要的结果是
index_count  model 
8            1520
0            1503
0            2090
0            1511
0            1529
请问如何做呢(顺序不要求和上面一样,只要都列出来就可以),谢谢

解决方案 »

  1.   

    select count(*) as index_count from C_ACCESS_LOG
    where model ='1503' and PAGEID  in (1505,1479,1462,1481,1569)
    这样得出的结果是
    index_count
    0
    select count(*) as index_count from C_ACCESS_LOG
    where model ='1520' and PAGEID  in (1505,1479,1462,1481,1569)
    这样得出的结果是
    index_count
    8而我现在想要的结果是
    index_count model 
    8           1520
    0           1503
    应该怎样做呢
      

  2.   

    ID Number
    pageid number
    model  varchar
    mid varchar
      

  3.   


    select count(*) as index_count,model from from C_ACCESS_LOG where model in (1503,2090,1511,1520,1529) and PAGEID in (1505,1479,1462,1481,1569) group by model;
      

  4.   

    楼上,您这句和我写的结果一样啊
    index_count  model 
    8            1520 
      

  5.   

    (
    select count(*),'1503' as index_count from C_ACCESS_LOG 
    where model ='1503' and PAGEID  in (1505,1479,1462,1481,1569) 
    )
    union
    (
    select count(*),'1520' as index_count from C_ACCESS_LOG 
    where model ='1520' and PAGEID  in (1505,1479,1462,1481,1569) 
    )
    这样写能做到我要的效果,可是一个model值就要1句,这样太烦了,能合为一句吗
      

  6.   

    把想统计的model存一个表里。和这个表做连接
    否则C_ACCESS_LOG 表里没有的model值,是不会出现在结果里的
      

  7.   

    试试这个:Select nvl(t1.index_count, 0), t2.Model From
    (select count(*) as index_count,model from C_ACCESS_LOG group by model,PAGEID 
    having model in (1503,2090,1511,1520,1529) and PAGEID in (1505,1479,1462,1481,1569)) t1
    Right Join
    (Select Model From C_ACCESS_LOG Where model in (1503,2090,1511,1520,1529)) t2
    On t1.Model = t2.Model;
      

  8.   


    select count(model) as index_count,model from from C_ACCESS_LOG where model in (1503,2090,1511,1520,1529) and PAGEID in (1505,1479,1462,1481,1569) group by model;
      

  9.   

    谢谢lg312200538,虽然不是完全对,但加上group by model就可以了,谢谢,给分