天天看點

看漫畫就能學SQL,簡直太cool了

<section data-role="outer" label="Powered by 135editor.com" style="font-size: 16px;"><p style="text-align: center;"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;"></span><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;">對于SQl, 很多人學不會的原因是從一開始就沒明白,學這東西能幹啥,學會了能有什麼用。甚至有些人不知道‘SQL’應該怎麼讀,以至于一開始興緻勃勃,但是學到一半放棄了。</span><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">注意:‘sql’真的不能讀成‘燒烤’、‘惜烤’、’撒扣’、’斯購‘,另外,’MYSQL’真的不能讀成’賣燒烤’,’賣西褲‘,有學員問:那我賣什麼,我回答說:你去死。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">如果你真的、實在是、絕對的看不懂英文的音标,那就暫且讀’色兒扣‘吧,這是針對英國文盲特别制作的讀法。(注意我在這裡并沒有瞧不起你的意思)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">是以,堅持學會的根本,不在于這個知識是否有多難,而在于它帶給你的意義有多大。如果做事情沒有意義,那麼你就沒有學習的動力。在資料分析的招聘中,SQL是必考的能力之一。是以學習SQL的意義,就在于你能否通過資料分析的面試,如果不能通過面試,你将窮困潦倒,颠沛流離,别人娶妻生子,兒孫繞膝,而你孤苦伶仃,滿目凄涼,垂垂老矣....</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">想要入門SQL,關鍵在于有沒有一個好的領路人帶你入門,是以ladys and鄉親們,放下手頭所有的農活,開始喜歡我吧,因為接下來,我将帶你輕松搞定SQL的各個文法。記住我最大的特點就是,通俗易懂的解釋一個事情。</span></p><p><br></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 50px;color: rgb(255, 120, 0);box-sizing: border-box !important;word-wrap: break-word !important;">01.</span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);font-size: 16px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;font-weight: 700;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">理論篇</span></span></strong></span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);font-size: 16px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;font-weight: 700;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">了解重要的概念</span></span></strong></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;line-height: 22px;box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);"><strong><span style="font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【資料】</span></strong></span><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">數字,文字,圖形,圖像,聲音這些都叫資料。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.4081196581196581" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxiaHZpvWLTskEM6ZscdwAavxrzhlcaiaiaUqTtSAaneKrRib7giaDSAeBRibQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="468" style="width: 468px !important; height: 191px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135519962-983457629.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;"><br></span></p><p style="text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><strong><span style="background-color: rgb(255, 255, 255);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;color: rgb(255, 76, 0);">【資料庫】</span></strong><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;"> 了解資料庫的一種最簡單的方法是 将它想象成一個電子化的“檔案櫃”,</span></p><p style="text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">這個“檔案櫃”是一個存放資料的實體位置,不管資料是什麼形式!就像法海手裡的金鉑,我管你是什麼妖,統統都得收進來!(電視劇裡的那個金鉑看起來像一個電飯鍋的内膽,有沒有很像)。也有人說資料庫存儲資料,就像冰箱是存儲食物一樣,,什麼肉啊,米啊,菜啊,都能存放,對此我也是十分十分的同意!!</span></p><p class=""><br></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5925" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxEUF7SfwibkibsDlkMq9xrlb7cCtFYZRQjJMibZN4Wficoial18JnkYloPmQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="400" style="width: 400px !important; height: 237px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135558736-540616755.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">有了資料庫後,所有終端裝置(手機,PAD, PC)都可以直接在這個系統上查找資料和修改資料。有人問我,老師,我是安卓手機,能連接配接資料庫嗎,當然能了,不許瞧不起安卓系統!!</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.42280285035629456" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxQgkKG1ushVCrFherlic8nRTzaSnOOt2VSLUodmWNibsOVSrARD3RDlWQ/640?wx_fmt=png" data-type="png" data-w="421" style="width: 421px !important; height: 178px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135656203-984228566.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;"><br></span></p><p style="text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><strong><span style="background-color: rgb(255, 255, 255);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;color: rgb(255, 76, 0);">【資料表】</span></strong><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;"> 表是由行和列組成的一張二維表,這是關系資料庫中最基本的資料模型</span></p><p class=""><br></p><p style="text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.48282097649186256" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxh0Pje8gf1HGXl1MqV5GqMib5PppDveGQKaPu4hHKicWLfibiaXcZCdqyGA/640?wx_fmt=png" data-type="png" data-w="553" style="width: 553px !important; height: 267px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135718602-688250737.png" crossorigin="anonymous"><strong><span style="background-color: rgb(255, 255, 255);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;color: rgb(255, 76, 0);">【主鍵】</span></strong><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;text-align: justify;">用來表示資料的唯一性,是資料庫中非常重要的概念。在生活中我們也會使用ID來辨別資料的唯一性,例如:國家用身份證來唯一辨別一個人,即使你有一個雙胞胎兄弟,但隻要你們的身份證号不一樣,你們就是兩個人。再比如銀行卡的卡号就是主鍵,如果兩個人卡号重複了,裡面有100萬,錢算誰的呢?這事就鬧大了。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.8349514563106796" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxby2iaZtAfRPgoyMbE6sNkX5ObZfsicWDG0OsLLb2Z6tGtQSsic5oq8GxQ/640?wx_fmt=png" data-type="png" data-w="309" style="width: 309px !important; height: 258px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135741015-1520236742.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);"><strong><span style="font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【外鍵】</span></strong></span><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"> 關聯到其他表主鍵的字段被稱為“ 外鍵 ”,如果A表的一個字段來源于B表,那麼這個字段就是A表的外鍵。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">例如:成績表中的字段學号 sno 就是外鍵, 因為這個字段的值來源于學生表的主鍵sno。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5655021834061136" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxw4vbbzTuabG94953h62SSncZgibD2dFqCMfG3oWaQ7nOiazuDNaYPokQ/640?wx_fmt=png" data-type="png" data-w="458" style="width: 458px !important; height: 259px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135828696-1989364955.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);"><strong><span style="font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【表關聯】</span></strong></span><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">什麼是聯系呢?你是你爸爸的兒子,你是你的兒子的爸爸。這就是生活中的聯系。其實,資料之間也是有聯系的。資料庫裡各個表之間如何建立聯系呢?</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">将多張表通過主鍵+外鍵關聯起來的方式,叫作表關聯。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">例如學生選課涉及的四張表,通過主鍵和外鍵關聯在一起,就構成了一個簡易的學生選課資料庫系統。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.6824196597353497" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxOOhMq9RscdFYTkr8sbf4nPY7SkkfY3AwLPQ01N7BUwM97MCgSyvIyQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="529" style="width: 529px !important; height: 361px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135855397-190525347.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">表關聯是關系資料庫中非常核心的理念 ,它可以表達非常複雜的資料關</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);"><strong><span style="background-color: rgb(255, 255, 255);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;">【概念模型】</span></strong></span><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;">表示方法:E—R方法(也叫實體聯系法)</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.39544513457556935" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxun1crDJ77d5OuLLanLgmaZP7XNYW6Q1WUb9A3CST3IibrQ6UoLbz4qg/640?wx_fmt=png" data-type="png" data-w="483" style="width: 483px !important; height: 191px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135930022-1392892282.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【一個E-R模型案例】:</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.8491879350348028" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhx0oiaHJkgKiazUoEFdtfRKX3SicSsUgdohppB9B8xZTib9qNLrqoUy9p8kA/640?wx_fmt=jpeg" data-type="jpeg" data-w="431" style="width: 431px !important; height: 366px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920135951329-489217512.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);"><strong><span style="font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【資料模型】</span></strong></span><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(主要指關系模型)</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">SQL語句的基礎是關系資料庫,關系資料庫的基礎是關系模型,關系模型可以由E-R圖得到。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">在關系資料庫中,一張表就是一個關系,是以表格的一些術語和關系的一些術語能表達同樣的意思,具體來說,有下面幾點不同:</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5397111913357401" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxHuiaIGxU9aJFxRX6tYYR08yJ9COdU8GmrAgecBd5lW3yvLept4icwkuQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="554" style="width: 554px !important; height: 299px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140013767-1034457158.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">上面講的都是資料庫方面的基本理論。理論有了,當然就得有對應的軟體實作才能用起來,不然再強大的理論都是一坨屎。這就好比,如果隻有設計草圖是無法蓋起樓房的,得有具體的施工團隊才能蓋起樓房。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">上面講的資料庫原理就是“設計草圖”,那麼對應的“施工團隊”是誰呢?</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">實作資料庫原理的“施工團隊”就是常用的資料庫軟體,例如MySQL、Oracle、SQLServer等都是實作上面理論的資料庫。各個資料庫軟體的使用差别大同小異,但是因為MySQL是開源的,免費的,是以成為各大公司使用的主流,面試也主要以’賣燒烤‘為主。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 50px;color: rgb(255, 120, 0);box-sizing: border-box !important;word-wrap: break-word !important;">02.</span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color:#000000;"><span style="letter-spacing: 0.5px;"><strong>SQL基礎篇</strong></span></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">我經曆過很多次資料分析師面試,經常會遇到這樣一道經典的SQL筆試題。注意:這可是華為的面試題,上點心吧。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【華為經典面試題】</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">A(使用者購買記錄)、B(商品對應ID)、C(ID對應價格)三個表,問本月内購買商品金額最多的前三名使用者分别是誰?</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【分析】</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">A表隻有使用者和商品名字的對應關系,需要關聯到C表求得價格,但A表和C表沒有公共字段,這時發現A表和B表有公共字段【商品名字】,而B表和C表有公共字段【商品ID】,于是先用A表Join B表,再Join C表得出一張多個字段的關聯表,用Group by求出使用者購買商品的總金額,再用Order by對使用者購買商品的總金額進行降序排列,最後用Limit截取總金額前三位的使用者。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">這道題看起來很難,但考到了都是一些SQL的基礎知識,包括Select、Groupby、Order by、Join、Limit。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">是以,作為資料分析獅(有人喜歡把自己叫作分析狗,真是太不尊重自己了,我聽了非常氣憤),如果你以後的發展方向不是資料工程師的話,SQL隻需要掌握基礎語句就可以糊弄面試了,具體包括:</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">查詢資料(select語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">過濾資料(where語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">彙總資料(group by 語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">排序資料(order by 語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">時間函數</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">1 查詢資料(select語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【文法】select 列名稱 from表名稱</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】select name from world; (選取world表中‘name’這一列)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">select * from world(選取world表中所有列)2 過濾資料(where語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【文法】select xxxx from xxx Where 條件表達式</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】select * from country where IndepYear &gt;1975</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.40828402366863903" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxx9XQ7Dd4VSaulYqGn9nWBRRGj4TvjHhILpZgwEdttWKd2Nyaaia8eQg/640?wx_fmt=png" data-type="png" data-w="507" style="width: 507px !important; height: 207px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140137817-823140211.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">3 使用distinct關鍵詞去重:</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【文法】select distinct 字段名 from 表名</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】select distinct class from student</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.37636761487964987" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxcbUQ0jCDvKl1s6xZ3jxCKJia71UxxTsErbLWI1UPlUHGWNeMtgdLbrA/640?wx_fmt=png" data-type="png" data-w="457" style="width: 457px !important; height: 172px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140202311-1725827803.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;">彙總資料( Group by 語句)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【定義】什麼是group by 子句,“Group By”從字面意義上了解就是根據“By”指定的規則對資料進行分組. 那麼,GROUPBY 是如何分組的呢?</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.6057866184448463" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxRT63Syic4cR58ibGmEnpLTKq5MibviaF5pYQxFlVy8GibJerxrE1JMoiaYZA/640?wx_fmt=jpeg" data-type="jpeg" data-w="553" style="width: 553px !important; height: 335px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140225939-1210662524.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">是以group by也叫分組函數。5 排序語句(order by)</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">Order by 指的是根據指定的列對結果進行排序,預設升序;如果希望降序,需要加上DESC關鍵字。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【文法】selectxxx from xxx</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">where xxx</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;text-align: left;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">order by xxx desc</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】篩選人口總數大于10萬的國家的資訊,并且按照人口總數進行降序排序。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">select * from countrywhere population &gt; 100000</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">order by population desc (先篩選符合條件的行,後排序)</span></p><p><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">使用Orderby 的幾種情況:(1)order by 作用于單個字段</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.2513562386980108" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxhL9G5MQqicaH7xFckNT9Derf76ZO3UOoTUicH4Yhvtygo08dFEQhqC8A/640?wx_fmt=png" data-type="png" data-w="553" style="width: 553px !important; height: 139px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140248359-1229697715.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(2)加desc關鍵字實作降序</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.30018083182640143" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxX9Qm0OzslGARuyndrdhd6q1oFJ1cibvESZ2jrLG2oYg6SN9cia0S6CWg/640?wx_fmt=png" data-type="png" data-w="553" style="width: 553px !important; height: 166px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140314733-420679069.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(3)order by 作用于雙字段</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.20938628158844766" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxCRGUQVq3bkQicNHlOrIEs6mSwRDfaz8CuJLPEJV4GqbshSGHpxTapug/640?wx_fmt=png" data-type="png" data-w="554" style="width: 554px !important; height: 116px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140335920-1596066063.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">先對年齡進行升序排序,然後針對相同年齡的,再根據成績升序排序</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">6時間函數</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">關于阿裡,京東,美團,快手等大部分網際網路公司,大部分資料需求都是和時間相關的,是以熟練掌握時間函數,非常的重要!!有人告訴我他不想工作,我奉勸你照照鏡子,看看鏡子中的自己,已經長得這麼醜了,難道還要沒錢嗎?</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">真是no zuo no die,我不會罵你的,我很有修養</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 50px;color: rgb(255, 120, 0);box-sizing: border-box !important;word-wrap: break-word !important;">03.</span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);font-size: 16px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;word-wrap: break-word !important;">SQL進階篇</span></strong></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;word-wrap: break-word !important;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">恭喜你,你已經看到進階篇了,現在你已經get到一個了不起的技能,媽媽再也不用擔心你沒法裝X了。下面這些資料是我們内部的一些分享資料,有人問我什麼内部,你在哪個公司上班,拜托大家不要像我二姑媽似的這麼八卦,要學會看重點!!進階部分需要大家了解mysql的執行原理,join的用法,SQL的執行順序等等,因為這是我們寫複雜SQL的基礎。你不會走,就想飛嗎,真的沒這麼容易!!</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(1)mysql中join的用法</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">之前網絡上流行用韋恩圖來表示各種連接配接查詢:</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.8103448275862069" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxEVtRwzsXXoksTAWxsplqI0roodl6k6sgXte4IzjmTdGiaQhBFtBZAYw/640?wx_fmt=jpeg" data-type="jpeg" data-w="406" style="width: 406px !important; height: 329px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920140410499-1948057571.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">但我覺得用下面這種方式表達連接配接查詢,更容易了解:</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.3447653429602888" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxTGN3DyJdGnYz1x8dda2XD3bKYXKXOFCByRv6Af79SaAhG0MiaK7DGZw/640?wx_fmt=png" data-type="png" data-w="554" style="width: 554px !important; height: 191px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920141843407-447030745.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.37725631768953066" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxncWC06sy9a7rh7Jryg0jZ7CDFIv270CwKN7WXMqg8uNib8BiauxrjW8A/640?wx_fmt=png" data-type="png" data-w="554" style="width: 554px !important; height: 209px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920141912308-759420408.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.33273056057866185" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxcuthJWu3FVN4gLXlJ1yApVy6L4zmPBaubKia0Kckp5WPeX2VZG1rOfQ/640?wx_fmt=png" data-type="png" data-w="553" style="width: 553px !important; height: 184px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920141940213-795484002.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.3833634719710669" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhx490XvL6BLhcb0QEdVCVdW3Qb2fzP8TRQY5UhgY0dYV0ibQicL6Ebo8Aw/640?wx_fmt=png" data-type="png" data-w="553" style="width: 553px !important; height: 212px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142008101-121881668.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5108303249097473" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxRIyrF3dnVDaOEcmgZ7IXcPjseib6IFHnnQh6icDkXw1H0fU1CKeEqoFQ/640?wx_fmt=png" data-type="png" data-w="554" style="width: 554px !important; height: 283px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142027918-1725561502.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">有沒有覺得連接配接查詢竟然如此簡單,還不是多虧了我這幾張圖嗎。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(2)Mysql的執行順序:</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">當sql邏輯複雜後,sql的執行順序就會非常重要,SQL執行順序和書寫順序又不一樣,是以慢慢扣吧,這也是進階的基礎呢。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.4423076923076923" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxZGltzSWt7g5lYyPc0MFuPx7ajy0t54lRNhibu3AAGzjOkic5AeM6IicYg/640?wx_fmt=jpeg" data-type="jpeg" data-w="520" style="width: 520px !important; height: 230px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142047984-1137671831.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 50px;color: rgb(255, 120, 0);box-sizing: border-box !important;word-wrap: break-word !important;">04.</span></p><p style="margin: 15px 8px;max-width: 100%;min-height: 1em;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;white-space: normal;widows: 1;text-align: center;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);font-size: 16px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;word-wrap: break-word !important;">SQL複雜查詢</span></strong></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">恭喜你,你都看到複雜查詢了,我覺得你很有潛力!!面對大量資料我們時常需要對他們進行彙總,分組,歸類,這時候就需要用到一些複雜的查詢方法。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">1聚合函數:【分類】聚合函數有哪些?</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.8625" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxEg25vLxArP0ib0epF3XvE1xicDcicPkmTcqy7QsyX0Ul5gXdSKWcdBN2w/640?wx_fmt=jpeg" data-type="jpeg" data-w="400" style="width: 400px !important; height: 345px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142110639-1441404573.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">2分組聚合</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【定義】指的是先使用group by 分組後,再使用聚合函數對每組資料聚合</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">分組語句和聚合函數常常一起使用</span></p><p class=""><br></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.4989059080962801" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxxFkdy6vlgVPhVNevYmfBAfvqbTZt1uT0HXic8wddboJSYLtOrEkBy5A/640?wx_fmt=png" data-type="png" data-w="457" style="width: 457px !important; height: 228px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142133908-1330280120.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【案例】:</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5623869801084991" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxbZBjgFPRtGQ9Qt5KlFs0JcXNgYZYjskMDX4C2v7E5lx7eLNxBicfFKg/640?wx_fmt=jpeg" data-type="jpeg" data-w="553" style="width: 553px !important; height: 311px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142157019-1429096789.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">3 使用having子句</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【定義】篩選符合條件的組,常常和group by 一起使用。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【示意圖】</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.628158844765343" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxnicSMMEHibOpljeckR1l5iaaicfo03hGJFiaJvXtFfhKYMicUeC4dmeviaB4g/640?wx_fmt=png" data-type="png" data-w="554" style="width: 554px !important; height: 348px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142219012-1108706528.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">4嵌套查詢:</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(1)【定義】什麼是嵌套查詢?</span></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">如果把一個查詢塊嵌套在另一個查詢塊的WHERE子句或HAVING短語的條件中,我們就稱為嵌套查詢。其中外層查詢稱為主查詢,内層查詢稱為子查詢。</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5350877192982456" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhx1VCxnrzda6HgdcH9BR6D5FRtZciayMp5c457ibns0SiapPxew4usBVfgw/640?wx_fmt=png" data-type="png" data-w="456" style="width: 456px !important; height: 244px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142240120-1203431246.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><strong><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(2)【執行順序】先執行内層查詢,再執行外層查詢:</span></strong></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.5268817204301075" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_png/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxAMBdicAichTdmX1V7XMb0K9ibibvCliaydSnsENq5UDa6UibCsW7EpJzqTAw/640?wx_fmt=png" data-type="png" data-w="465" style="width: 465px !important; height: 245px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142302444-2031746129.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">(3)嵌套查詢用來解決哪些問題?</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.7511737089201878" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxfUXhE5WaQKKFKWXv1acWkTPovc0icQZI1FRBp6Liav956iaZriaHIcK0tw/640?wx_fmt=jpeg" data-type="jpeg" data-w="426" style="width: 426px !important; height: 320px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142331452-1287107110.png" crossorigin="anonymous"></p><p style="font-weight: bold;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">【Sql 語句】</span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-ratio="0.6841155234657039" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxzgCfzrvUBWpA8YGRuyfc7kBYbPaXO460UW02xORRfC4BAU6lNlQn0A/640?wx_fmt=jpeg" data-type="jpeg" data-w="554" style="width: 554px !important; height: 379px !important;" _width="auto" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142401532-487349221.png" crossorigin="anonymous"></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">掌握了上面這些文法,基本上你可以糊弄各種形式的面試了,最常見的考SQL的方法就是,給你一個虛拟的資料庫表結構,然後讓你按給出的條件查詢出資料,并用手寫的形式寫出在紙上。是以面試前把常用的SQL語句記清楚就OK了。</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">怎麼,覺得自己牛逼的不行,再練點更難的題吧</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">推薦一個很友善的實踐SQL的網站:資料庫SQL實戰-牛客網</span></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);"><br></span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><img class="img_loading" data-croporisrc="https://mmbiz.qpic.cn/mmbiz_jpg/cx8SumXqBLrOHy7rlrYcSAktuEjqCjhxdPDjerVVKDa9dBGdO4UFPeDKceyYqYGjoIeAbuZ5PAQVAYfhx2rNFw/640?wx_fmt=jpeg" data-cropx1="0" data-cropx2="553" data-cropy1="69.63703703703705" data-cropy2="393.24444444444447" data-ratio="0.5858951175406871" data-s="300,640" data-src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142426910-805238104.png" data-type="jpeg" data-w="553" style="width: 540px !important; height: 316.383px !important;" _width="540px" src="https://img2018.cnblogs.com/blog/1112483/201909/1112483-20190920142426910-805238104.png" crossorigin="anonymous"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><br></p><p style="max-width: 100%;font-size: 14px;color: rgb(136, 136, 136);box-sizing: border-box;margin-left: 8px;margin-right: 8px;line-height: 1.75em;word-wrap: break-word !important;"><span style="color: rgb(62, 62, 62);font-family: Arial, Helvetica, sans-serif;font-size: 15px;letter-spacing: 1.5px;widows: 1;background-color: rgb(255, 255, 255);">實際上還有很多類似這樣的網站,是用來強化SQL練習的,但因為他們并沒有給我廣告費,我為什麼要給他們做廣告呢?</span></p></section>
  原文位址:https://mp.weixin.qq.com/s/t8JCJSP__qh11U2zl8hCeQ          </div></div>