SQL筆試題1

          ?

          ?1 已知一個表的結構為:?
          ?2 姓名?科目?成績?
          ?3 張三?語文? 20 ?
          ?4 張三?數學? 30 ?
          ?5 張三?英語? 50 ?
          ?6 李四?語文? 70 ?
          ?7 李四?數學? 60 ?
          ?8 李四?英語? 90 ?
          ?9 怎樣通過select語句把他變成以下結構:?
          10 姓名?語文?數學?英語?
          11 張三? 20 ? 30 ? 50 ?
          12 李四? 70 ? 60 ? 90
          答案:

          posted on 2006-12-21 18:05 youngturk 閱讀(3993) 評論(6)  編輯  收藏 所屬分類: SQL筆試題

          評論

          # re: SQL筆試題1 2008-02-24 15:05 stoneyang

          select sname, sum(case skemu when '語文' then sgrade else 0 end) as 語文,
          sum(case skemu when '數學' then sgrade else 0 end) as 數學,
          sum(case skemu when '英語' then sgrade else 0 end) as 英語
          from students group by sname order by sname desc  回復  更多評論   

          # re: SQL筆試題1 2008-03-10 11:59 思寬

          @stoneyang
          謝謝探討  回復  更多評論   

          # re: SQL筆試題1 2008-09-16 17:14 dfadsfa

          select t1.姓名,t1.語文,t2.數學,t3.英語from
          (select 姓名as 姓名,成績as 語文from t where 科目='語文') t1
          join
          (select 姓名as 姓名,成績as 數學from t where 科目='數學') t2
          on t1.姓名=t2.姓名
          join
          (select 姓名as 姓名,成績as 英語from t where 科目='英語') t3
          on t2.姓名=t3.姓名
            回復  更多評論   

          # re: SQL筆試題1 2009-02-24 16:24 feifeirao

          樓主的,應該是這樣的吧-------------------------
          select A.姓名,A.成績 as 語文,B.成績 as 數學,C.成績 as 英語
          from student A,student B,student C
          where A.姓名 = B.姓名 and B.姓名 = C.姓名
          and A.科目 = ' 語文 ' and B.科目 = ' 數學 '
          and C.科目 = ' 英語 '   回復  更多評論   

          # re: SQL筆試題1 2009-03-19 15:44 fuchu12000

          select distinct aa3.姓名,aa3.語文,aa3.數學,aa4.英語 from
          (select distinct aa1.姓名,aa1.語文,aa2.數學 from
          (select 姓名,成績 as 語文 from Table_name where 科目='語文') aa1
          left join
          (select 姓名,成績 as 數學 from Table_name where 科目='數學') aa2
          on aa1.姓名=aa2.姓名) aa3
          left join
          (select 姓名,成績 as 英語 from Table_name where 科目='英語') aa4
          on aa3.姓名=aa4.姓名  回復  更多評論   

          # re: SQL筆試題1 2009-05-30 11:13 sdf

          select 姓名,(case when 語文 then 成績) as 語文,(case when 數學 then 成績) as 數學,,(case when 英語 then 成績) as 英語 from table  回復  更多評論   

          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 辽宁省| 张家港市| 万盛区| 桓仁| 巫山县| 浑源县| 清流县| 兴安县| 梁河县| 瑞丽市| 巫山县| 清丰县| 黑水县| 郑州市| 大丰市| 龙山县| 靖安县| 嘉荫县| 灌南县| 汽车| 剑川县| 通河县| 涿鹿县| 自治县| 札达县| 磐安县| 营山县| 环江| 澄迈县| 武威市| 凤阳县| 连州市| 锦州市| 尉氏县| 达日县| 新晃| 永寿县| 蒲城县| 彭阳县| 宜兰县| 湘西|