-----建立表---- ----------表格頭英文換中文顯示select name as '名字',age 年齡,class from student -----if not exists判斷表存在否--字符串用char也行--- --若是用自增加,只能用包裝類型integer,不能用int-- create table if not exists student( id Integer primary key autoincrement not null, name String not null, sex String not null, age int not null, hight real , class String ) ------用逗號分隔,最後一個字段不用寫----- ---刪除表------ drop table student ------插入一條數據------ insert into student (name,sex,age,hight,class) values('張三','男',21,178,'cc111') ------插入多條數據------ insert into student (name,sex,age,hight,class) values('李四','男',23,170,'cc111'),('王五','女',20,173,'cc111') ,('趙六','男',22,179,'cc112'), ('朱七','女',24,171,'cc112') ------查詢全部數據------ select * from student ------------------- select * from student where age=22 ------修改數據------ ---- update 表名 set 字段 =-加條件 where --- update student set hight=null where id=5 -----班級爲cc111,男,hight不爲null,則每一個高度都增加1 update student set hight=hight+1 where class='cc111' and sex='女' and hight not null ---------------凡是cc111班年齡減1---- update student set age=age-1 where class='cc111' -------------凡是cc111班或者性別爲女的則高度+1---------------------- update student set hight=hight+1 where class='cc111' or sex='女' --------修更名字的第一個字爲王的年齡減1歲 update student set age =age-1 where name like '王%' -----------修更名字爲張三或者爲李四的班級爲cc112---------------- update student set class='cc112' where name in('張三','李四') ----刪除全部 delete from student -------刪除名字含朱的 delete from student where name like '%朱%' --查詢全部 select * from student ---女的 select * from student where sex='女' ------查詢cc111班的人的名字 select name from student where class='cc111' --查詢大於21,小於23的人 select * from student where age>=21 and age<=23 ---查詢名字含朱的 select * from student where name like '%朱%' ---------查詢cc111班女生,而且按年齡從小到大排序- order by,降序 desc,默認就是升序- select * from student where sex='女' and class='cc111' order by age desc -------------查詢全部女生,而且按年齡從大到小排序-,只顯示前3個---- ----limit 偏移量0表示第一個,顯示的個數----- select * from student where sex='女' order by age desc limit 0,2 ---查詢出cc112班的總人數-------- select count(*) from student where class='cc112' ------查詢出cc112班的全部人的年齡總和--------------- select sum(age) from student where class='cc112' -------查詢出cc111班的平均年齡------------- select avg(age) from student where class='cc112' -----查詢全部的班級的男性人數,而且按班級進行分組 group by --------- select class,count(*) from student where sex='男' group by class -----查詢cc112班年齡最大的學員----------- select max(age),name from student where class='cc112' -----查詢班上的全部學員,按班級進行分組,再進行降序,而且只列出總人數大於等於1個班級----------- select class,count(*) from student group by class having count(*)>=1 order by count(*) desc