The second day to learn MySQL

      MySQL圖形化工具ide

          Navicat 函數

    數據操做語言工具

        Create table 表名:  建立表spa

          Insert into 表名(列名1, 列名2, 列名3...)values(列名1值,列名2值, 列名3值.)  :新增值orm

          Delete from 表名  :  刪除表排序

          Update 表名 set 列名1=修改的值,列名2=修改的值;    :修改值ci

       Select * from 表名   :查詢整個表字符串

       Select * from 表名 where 列名1=值 and 列名2=值....     :根據條件查詢指定的數據it

     Select 列名1,列名2 from      :查詢指定的列的數據table

     Select 列名 (as)別名,列名2 (as)別名2... from 表名;        : 給指定返回列取別名(as)表示無關緊要

       SELECT * FROM 表名 where 字段 > < >= <= !=或<>               :在條件中使用運算符

       and or not  (和,或者,不)

       ag:select * from student where age<=21 and sex='女' (在表student中查詢年齡小於等於21歲的女生)。

     ag:select * from student where age<=21 or sex='女' (在表student中查詢年齡小於等於21歲的學生或女生) (兩者都會被查詢出來)。

     對空值的查詢:is null  對應列是否null查詢

     select * from 表名 where 對應列 is not null  

     select * from 表名 where 列名 BETWEEN A and B;   查詢表中對應列A和B之間的值(包含A和B的值)。

     select * from 表名 where 列名 in(a,b,c);  查詢表中對應列知足a、b、c中任一一個的值。

     模糊查詢  like 

     _:指代明確值的位置或已知字符串長度

     %:指代不明確值的位置或長度

     select * from 表名 where 列名 like '_A%';  查詢表中對應列第二個字爲A的值。

     select * from 表名 where 列名 like 'A_%';  查詢表中對應列第一個字爲A的值。

    select * from 表名 where 列名 like '%A%';  查詢表中對應列含有A的值。

     查詢中使用算術表達式:+ - * /  :在表中對相應列進行運算。

     處理重複值:DISTINCT   排除重複展現,只展現一次

     select DISTINCT sex from 表名;      只展現一次表中的性別。

     select * from 表名 limit 10;        查詢數據的前10

     select * from 表名 limit 10,10;    查詢表中第11至第20位的數據 (有多少數據顯示多少數據,直到第20個)

     create table 目標表名 select*from 現有表名;   把現有表複製到目標表中。

     create table 目標表名 select*from where flase;   只複製表的結構。(flase如1=2,當條件不知足時,不復制值)

     select * from 表名 order by  :升序排序(默認)

     select * from 表名 order by desc   將需拍下


經常使用函數

      獲得須要查詢字符的ascii碼

      select ascii('字符');

      根據字符集查詢獲得的字符的長度

      select char_length('字符');

      拼接字符串

      select concat ('字符1','字符2','字符3'......);

      大寫轉小寫

      select lower('ABC');

      小寫轉大寫

      select upper('abc');

      查詢表中對應列的對應數據的最後一個字

      select right(對應列,1) from 表名;

      查詢表中對應列的對應數據的第一個字

         select left(對應列,1) from 表名;



      聚合函數:

 COUNT  統計數量select count(列名) from 表名;

SUM    求和:select sum(列名) from 表名;

MAX    最大值select max(列名) from 表名;

MIN    最小值select min(列名) from 表名;

AVG    平均select avg(列名) from 表名;

相關文章
相關標籤/搜索