sum(case parentId when 0 then 1 else 0 end)
sum(case when parentId=0 then 0 else 1 end)
这两句是啥意思?有什么不同?

解决方案 »

  1.   

    有區別sum(case parentId when 0 then 1 else 0 end)
    等同於
    sum(case when parentId=0 then 1 else 0 end)when放在前後沒關係的。
      

  2.   

    sum(case parentId when 0 then 1 else 0 end)
    统计 parentId=0 的记录条数sum(case when parentId=0 then 0 else 1 end)
    统计 parentId<>0 的记录条数
      

  3.   

    then else后面的1和0是什么意思?
      

  4.   

    sum(case parentId when 0 then 1 else 0 end)
    sum(case when parentId=0 then 0 else 1 end)
    ---------------------------------------这两句结果不同,但语法都正确then else后面的1和0是什么意思?
    -----------------------
    是说如果parentId=0的话,就等于1 如果parentId<>0 ,就等于0
      

  5.   

    是说如果parentId=0的话,就等于1 如果parentId<>0 ,就等于0
    是什么等于1?等于0?是ParentId吗?
      

  6.   

    lixk2000() ( ) 信誉:100    Blog   加为好友  2007-6-3 16:05:22  得分: 0  
     
     
       
    是说如果parentId=0的话,就等于1 如果parentId<>0 ,就等于0
    是什么等于1?等于0?是ParentId吗?  
     
    -----------錯了,實際應該上
    如果parentId=0的话,就加上1 如果parentId<>0 ,就加上0
    其實 Yang_(扬帆破浪) ( ) 信誉:132    Blog   加为好友  2007-6-2 16:54:01  得分: 0  
     
     
       
    sum(case parentId when 0 then 1 else 0 end)
    统计 parentId=0 的记录条数sum(case when parentId=0 then 0 else 1 end)
    统计 parentId<>0 的记录条数
    已經說的很明白了  
     
      

  7.   


    sum(case parentId when 0 then 1 else 0 end)
    它是統計parentId<>0的紀錄條數
    但是具體計算是這樣的 返回結果=(先統計出parentId<>0的紀錄條數 * else後面的哪個值)+then後面的那個值sum(case when parentId=0 then 0 else 1 end)
    它是統計parentId<>0的紀錄條數
    但是具體計算是這樣的 返回結果=(先統計出parentId<>0的紀錄條數 * else後面的哪個值)+then後面的那個值
      

  8.   

    樓上簡直就是在誤導。首先
    sum(case parentId when 0 then 1 else 0 end)
    它是統計parentId=0的紀錄條數而它的就是就只是
    返回結果=統計出parentId=0的紀錄條數
      

  9.   

    每一个是:
    计算parentId=0的记录条数
    每二个是:
    计算parentId<>0的记录条数
      

  10.   

    每一个是:
    计算parentId=0的记录条数
    每二个是:
    计算parentId<>0的记录条数
    ----------------
    就是呀
      

  11.   

    每一个是:
    计算parentId=0的记录条数
    每二个是:
    计算parentId<>0的记录条数为什么是这个结果?
      

  12.   

    lixk2000() ( ) 信誉:100    Blog   加为好友  2007-06-07 08:43:43  得分: 0  
     
     
       每一个是:
    计算parentId=0的记录条数
    每二个是:
    计算parentId<>0的记录条数为什么是这个结果?
      
     
    -----------
    上面不是有解釋嗎?
    sum(case parentId when 0 then 1 else 0 end)逐條對比表中每條紀錄,如果parentId=0的话,就加上1 如果parentId<>0 ,就加上0,最後的到的統計結果就是“计算parentId=0的记录条数”。
      

  13.   

    每一个是:
    计算parentId=0的记录条数
    每二个是:
    计算parentId<>0的记录条数
      

  14.   

    sum(case parentId when 0 then 1 else 0 end)
    统计 parentId=0 的记录条数sum(case when parentId=0 then 0 else 1 end)
    统计 parentId<>0 的记录条数正解  学习
      

  15.   

    sum(case parentId when 0 then 1 else 0 end)
    统计 parentId=0 的记录条数sum(case when parentId=0 then 0 else 1 end)
    统计 parentId<>0 的记录条数