MySQL資料庫基礎知識學習筆記(三)

來源:互聯網
上載者:User

標籤:select   insert   update   delete   count   

SQL語句實戰——DML語句(重點)

選擇:select * from table1 where 範圍

插入:insert into table1(filed1,filed2)values (filed1,filed2)

解釋:filed1,filed2 欄位名;filed1,filed2欄位值

刪除:delete from table1 where 範圍

更新:update table1 set field1=value1 where 範圍

尋找:select * from table1where filed1 like ‘%value1%’ 

 解釋:尋找包含value1的模糊比對

如果尋找以value1開頭,則用‘value1%’;

如果尋找以value1結尾:則用‘%value1’;

排序:select * from table1 order by filed1,filed2[desc]

解釋:[desc]倒敘  [asc]正序

總數:select count(*) as totalcount from table1

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

最大:select max(field1) as maxvalue from table1

最小:select min(field1) as minvalue from table1


實戰練習:

1) 插入

對persion_info插入四條資料:

語句:(person_id是自增長的,所以不用寫)

insert into person_info(name,country,salary)

values ( '小趙 ', 'China',1200.01),

('小錢 ', '上海 ',1600.32),

( '小孫 ', '廣州 ',2000.40),

( '小李 ', '珠海 ',1670.88);

執行結果:


2) 更新:

如果想把小趙的country欄位換成北京,則執行語句:

update person_info set country = '北京' where name = '小趙';

執行後的結果如下:


3) 排序

對name進行order by排序

語句:select * from person_info order by name desc;

運行結果:


4) 尋找

尋找包含“趙”的模糊比對資料,語句“”

Select * from person_info where name like ‘%趙%’;

運行結果:

5) 總數

求person_info表裡的資料總條數

語句:Select count(*) as totalcount from person_info;

執行結果:


可見結果是4,同時欄位名為totalcount。

 

6) 求和

語句:select sum(salary) as sumvalue from person_info;

執行結果:










MySQL資料庫基礎知識學習筆記(三)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.