看漫畫就能學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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM