MySQL 簡單語句(2)

來源:互聯網
上載者:User

標籤:

建立資料庫:   create database 庫名;

建立表:       create table 表名   (列名 資料類型(長度) primary key,列名 資料類型 是否為空白…… );

               注意:最後一列不要加逗號。多條語句一起執行,加分號。代碼符號半形。

               建立表的關鍵字:主鍵 primary 

                              非空 not null

                              自增長列 auto_increment   

                              外鍵關係 foreign key(列名)references 表名(列名)

添加資料:     insert into 表名 values(‘’,‘’,‘’)    括弧內的值得個數和表的列數相同

              insert into 表名 (列名,列名) values(‘’,‘’)    添加指定的列

修改資料:     update 表名 set 列=新值 where 條件;

刪除資料:     delete from 表 where+條件;

普通查詢:     select (結果顯示列) from 表名 

條件查詢:     select (結果顯示列) from 表名 where 條件

排序查詢:     selert (結果顯示列) from 表名 order by 列名 (asc/desc),列名 (asc/desc)......

彙總函式:     select count(*)from 表名       #取個數

              select sum(列名) from 表名      #查詢列的和

              select avg(列名) from 表名      #查詢平均值

              select max(列名) from 表名      #查詢最大值

              select min(列名) from 表名      #查詢最小值

分頁查詢:     select * from 表名 limit n,m     #跳過n條取m條  

分組查詢:     select 列名 from 表名 group by 列名    #簡單的分組查詢

              select brand from car group by brand having count(*)>2     #查詢系列裡面車的數量大於2的系列 

去重查詢:     select distinct 列名 from 表名

修改列名:     select 列名 as ‘新列名’ from 表名

模糊查詢:     select * from 表名 where name like ‘_奧迪%’       #任意組合  %代表無限個字元 _代表一個字元 任意組合    

離散查詢:     select * from 表名 where 列名 in/not in (‘’,‘’,‘’)       

大於所有資料的:select * from 表名 where 列名>all(50,40,30) 

MySQL 簡單語句(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.