真善美

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

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

          商品分類如下:

          問題1:查詢商品中各類飲料,并對飲料的類型進(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 真善美 閱讀(273) 評論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫學(xué)習(xí)
          主站蜘蛛池模板: 南召县| 沙洋县| 三门峡市| 荣昌县| 开原市| 仪陇县| SHOW| 嵊泗县| 遂溪县| 图木舒克市| 龙川县| 凤庆县| 易门县| 天等县| 宜丰县| 阳曲县| 清水县| 河源市| 松滋市| 磴口县| 旅游| 扶绥县| 肥东县| 南郑县| 临海市| 德江县| 丹东市| 平南县| 吉林市| 太康县| 彭阳县| 连江县| 深圳市| 宽甸| 当涂县| 松溪县| 花垣县| 库尔勒市| 公主岭市| 商丘市| 四川省|