久久机这里只有精品,国产69精品一区二区亚洲孕妇,91精品国产综合久久婷婷香蕉,午夜久久久久久电影

最新活動:電腦PC端+手機端+微網(wǎng)站+自適應網(wǎng)頁多模板選擇-建站388元起價!!!
當前位置:主頁 > 網(wǎng)站建設 > 分享整理的12條sql語句連同數(shù)據(jù)建站知識

分享整理的12條sql語句連同數(shù)據(jù)建站知識

時間:2023-05-23 12:05:23 閱讀: 文章分類: 網(wǎng)站建設 作者: 網(wǎng)站技術(shù)員

導讀:1建站知識原本sql寫得也不好,近幾年數(shù)據(jù)庫用得少,sql更是荒廢了,最近復習sql,網(wǎng)上例 子很多,但都只是提供sql例子,沒有配網(wǎng)站建設教程公司網(wǎng)站建設。

網(wǎng)站建設教程公司網(wǎng)站建設俺覺得自 己試著寫寫sql,調(diào)試調(diào)試還是有幫助的,讀人家sql例子好像讀懂了,自己寫就未 必思路正確,調(diào)試得通,寫得簡潔。 跟著網(wǎng)上流行的學生選課表的例子復習了一下: 這篇文字在網(wǎng)上被轉(zhuǎn)載爛了,里面有些sql適合用在應用系統(tǒng)里,有些“報表”的感 覺更重些,主要是想復習前者。前20條大體還挺好,后30條明顯偏報表風格了,而 且后面選例良莠不齊,選了12個例子做練習,(其實很多語法,case, any/all, union之類的都沒包括),用mysql數(shù)據(jù)庫,并共享自己造出來的數(shù)據(jù)。關于這12條 sql, 修正了原文中有紕漏的地方。 sql是基本技能,若能寫得好也挺精彩的,還在繼續(xù)練習。絕不提倡努力寫復雜sql 解決業(yè)務問題。應用系統(tǒng)里如果存在很復雜的sql,往往揭示了業(yè)務邏輯向下泄露 到sql層的問題,不利于維護和擴展,雖然這樣確實常能提高運行效率。具體情況 自行取舍。 下面的例子都是比較通用的sql, 其實針對特定的數(shù)據(jù)庫,需要學的也挺多,比如 oracle db的decode函數(shù), rowid, rownum, connect by 雖然不通用,但是很實用。 數(shù)據(jù)可以在這里下載,只是用作練習,沒做任何外鍵關聯(lián): 整理的sql在下面: Student(S#,Sname,Sage,Ssex) 學生表 Course(C#,Cname,T#) 課程表 SC(S#,C#,score) 成績表 Teacher(T#,Tname) 教師表 1. 選出每門功課都及格的學號 select distinct `s#` from sc where `s#` not in (select `s#` from sc where score <60) 2. 查詢“1”課程比“2”課程成績高的所有學生的學號; SELECT c01.`s#` from (select `s#`, `score` from sc where `c#`=1) c01, (select `s#`, `score` from sc where `c#`=2) c02 where c01.`s#` = c02.`s#` and c01.score > c02.score 3. 查詢平均成績大于60分的同學的學號和平均成績; select `s#`, avg(score) from sc group by `s#` having avg(score) > 60 4. 查詢所有同學的學號、姓名、選課數(shù)、總成績; select student.`s#`, student.`Sname`, count(`c#`), sum(score) from student left outer join sc on student.`s#` = sc.`s#` group by student.`s#`, sc.`s#` 5.查詢沒學過“葉平”老師課的同學的學號、姓名; select student.`s#`, student.`Sname` from student where student.`s#` not in (select distinct(sc.`s#`) from teacher, course, sc where Tnamseo網(wǎng)站優(yōu)化軟件e='葉平' and teacher.`t#` = course.`t#` and sc.`c#`= course.`c#` ) 6. 查詢學過“001”并且也學過編號“002”課程的同學的學號、姓名 select student.`s#`, student.sname from student, scseo網(wǎng)站排名優(yōu)化軟件 where student.`s#` = sc.`s#` and sc.`c#` = 1 and exists (select * from sc sc_2 where sc_2.`c#`=2 and sc.`s#`=sc_2.`s#`) 7. 查詢學過“葉平”老師網(wǎng)站推廣優(yōu)化seo所教的所有課的同學的學號、姓名 (巧妙) select `s#`, sname from student where `s#` in (select `s#` from sc, teacher, course where tname='葉平' and teacher.`t#`=course.`t#` and course.`c#`= sc.`c#` group by `s#` having count(sc.`c#`)= (select count(`c#`) from teacher, course where tname='葉 平' and teacher.`t#`=course.`t#`) ) 8. 查詢課程編號“002”的成績比課程編號“001”課程低的所有同學的學號、姓名 (有代表性) select `s#`, sname from (select student.`s#`, student.sname, score, (select score from sc sc_2 where student.`s#`=sc_2.`s#` and sc_2.`c#`=2) score2 from student , sc where sc.`s#`=student.`s#` and sc.`c#`=1) s_2 where score2 < score 9.查詢沒有學全所有課的同學的學號、姓名 select student.`S#`, Sname from student, sc where student.`s#` = sc.`s#` group by `s#`, sname having count(`c#`) < (select count(`c#`) from course) 10. 查詢至少有一門課與學號為“002”的同學所學相同的同學的學號和姓名; select distinct(sc.`s#`), sname from student, sc where student.`s#`=sc.`s#` and `c#` in (select `c#` from sc where `s#`=002) 11. 把“SC”表中“葉平”老師教的課的成績都更改為此課程的平均成績; update sc inner join (select sc2.`c#`, avg(sc2.score) score from sc sc2, teacher, course where sc2.`c#`=course.`c#` and tname='葉平' and teacher.`t#` = course.`t#` and course.`c#`=sc2.`c#` group by course.`c#`) sc3 on sc.`c#`=sc3.`c#` set sc.score=sc3.score 12. 查詢2號的同學學習的課程他都學了的同學的學號;(注意理解:where語句的 第一個條件過濾掉不滿足c#的記錄,再group by,就比較清晰) select `S#` from SC where `C#` in (select `C#` from SC where `S#`=2) group by `S#` having count(*)=(select count(*) from SC where `S#`=2); 作者 人在江湖相關網(wǎng)站建設教程公司網(wǎng)站建設。

關鍵詞標簽: 標簽 語句

聲明: 本文由我的SEOUC技術(shù)文章主頁發(fā)布于:2023-05-23 ,文章分享整理的12條sql語句連同數(shù)據(jù)建站知識主要講述語句,標簽,分享整理的12條sql語句連同數(shù)據(jù)建站知網(wǎng)站建設源碼以及服務器配置搭建相關技術(shù)文章。轉(zhuǎn)載請保留鏈接: http://www.bifwcx.com/article/web_5527.html

我的IDC 網(wǎng)站建設技術(shù)SEOUC.COM
專注網(wǎng)站建設,SEO優(yōu)化,小程序設計制作搭建開發(fā)定制網(wǎng)站等,數(shù)千家網(wǎng)站定制開發(fā)案例,網(wǎng)站推廣技術(shù)服務。
  • 5000+合作客服
  • 8年從業(yè)經(jīng)驗
  • 150+覆蓋行業(yè)
  • 最新熱門源碼技術(shù)文章

    主站蜘蛛池模板: 忻州市| 蓬溪县| 昔阳县| 崇礼县| 蒲城县| 图片| 大同县| 舟山市| 社旗县| 松溪县| 大洼县| 留坝县| 洪湖市| 浦城县| 巫山县| 望都县| 钟山县| 四平市| 万载县| 永仁县| 勃利县| 张家界市| 嘉兴市| 舞钢市| 尼木县| 正宁县| 四子王旗| 无棣县| 醴陵市| 海南省| 新乡市| 桐庐县| 靖江市| 淮安市| 左云县| 海丰县| 文安县| 绵阳市| 舒兰市| 瑞昌市| 商都县|