真善美

          勇于承擔(dān)責(zé)任; 如果你做不到,要提前跟別人說明,不要等到事情發(fā)生后再解釋。

            BlogJava :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理 ::
            55 隨筆 :: 0 文章 :: 29 評(píng)論 :: 0 Trackbacks

          商品分類如下:

          問題1:查詢商品中各類飲料,并對(duì)飲料的類型進(jìn)行標(biāo)注。
          程序?qū)崿F(xiàn)如下:

          if(id=="b")
          {
             a++;
          }
          else if(id=="d")
          {
             d++;
          }
          else if(id=="c")
          {
             if(subid=="e")
             {
                e++;
             }
             else if(subid=="f")
             {
                f++;
             }
             else  if(subid=="g")
             {
                g++;
             }
          }


          sql實(shí)現(xiàn):
          select  (case when id='b' then 'B' 
                      when id='d' then 'D'
                      when id='c' then decode(subid,'e','E','f','F','g','G','Ohter')
                      else null end) type
            from tab


          問題2:查詢各類商品的數(shù)量
          select
                count(case when a.id='b'then 1 else null end) as B,
                count(case when a.id='d'then 1 else null end) as D,
                count(case when a.id='c' and subid='e' then 1 else null end) as E,
                count(case when a.id='c' and subid='f' then 1 else null end) as F,
                count(case when a.id='d' and subid='g' then 1 else null end) as G
                from atab a
          posted on 2011-02-19 17:20 真善美 閱讀(269) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫學(xué)習(xí)
          主站蜘蛛池模板: 藁城市| 隆安县| 潮安县| 临清市| 西宁市| 日喀则市| 新巴尔虎右旗| 定边县| 德格县| 偃师市| 临海市| 吉木乃县| 凭祥市| 和硕县| 临泽县| 北海市| 巴彦县| 土默特左旗| 怀仁县| 会泽县| 盘锦市| 灵川县| 班戈县| 九江县| 乐山市| 新竹县| 扎赉特旗| 尉氏县| 玉溪市| 吉木萨尔县| 大名县| 漾濞| 海南省| 全州县| 鸡东县| 常山县| 榆中县| 天门市| 万荣县| 汉中市| 洞头县|