MySQL數據庫基礎知識學習筆記(三)

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

選擇:select * from table1 where 範圍

插入:insert into table1filed1,filed2values (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);

執行結果:

image.png

2) 更新:

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

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

執行後的結果如下:

image.png


3) 排序

name進行order by排序

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

運行結果:


image.png

4) 查找

查找包含“趙”的模糊匹配數據,語句“”

Select * from person_info where name like %%;

運行結果:

image.png

5) 總數

person_info表裏的數據總條數

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

執行結果:

image.png

可見結果是4,同時字段名爲totalcount

 

6) 求和

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

執行結果:

image.png








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章