1. 程式人生 > >MySQL-6-語句數據行操作

MySQL-6-語句數據行操作

int log delet between 排序 max sid AR 通配

語句數據行操作

今日內容

SQL語句數據行操作補充
            create table tb12(
                id int auto_increment primary key,
                name varchar(32),
                age int
            )engine=innodb default charset=utf8;
    
        增
            insert into tb11(name,age) values(alex,12
); insert into tb11(name,age) values(alex,12),(root,18); insert into tb12(name,age) select name,age from tb11; 刪 delete from tb12; delete from tb12 where id !=2 delete from tb12 where id =2 delete
from tb12 where id > 2 delete from tb12 where id >=2 delete from tb12 where id >=2 or name=alexupdate tb12 set name=alex where id>12 and name=xx update tb12 set name=alex,age=19 where id>12 and name=
xxselect * from tb12; select id,name from tb12; select id,name from tb12 where id > 10 or name =xxx; select id,name as cname from tb12 where id > 10 or name =xxx; select name,age,11 from tb12; 其他: select * from tb12 where id != 1 select * from tb12 where id in (1,5,12); select * from tb12 where id not in (1,5,12); select * from tb12 where id in (select id from tb11) select * from tb12 where id between 5 and 12; 通配符: select * from tb12 where name like "a%" select * from tb12 where name like "a_" 分頁: select * from tb12 limit 10; select * from tb12 limit 0,10; select * from tb12 limit 10,10; select * from tb12 limit 20,10; select * from tb12 limit 10 offset 20; # page = input(請輸入要查看的頁碼) # page = int(page) # (page-1) * 10 # select * from tb12 limit 0,10; 1 # select * from tb12 limit 10,10;2 排序: select * from tb12 order by id desc; 大到小 select * from tb12 order by id asc; 小到大 select * from tb12 order by age desc,id desc; 取後10條數據 select * from tb12 order by id desc limit 10; 分組: select count(id),max(id),part_id from userinfo5 group by part_id; count max min sum avg **** 如果對於聚合函數結果進行二次篩選時?必須使用having **** select count(id),part_id from userinfo5 group by part_id having count(id) > 1; select count(id),part_id from userinfo5 where id > 0 group by part_id having count(id) > 1; 連表操作: select * from userinfo5,department5 select * from userinfo5,department5 where userinfo5.part_id = department5.id select * from userinfo5 left join department5 on userinfo5.part_id = department5.id select * from department5 left join userinfo5 on userinfo5.part_id = department5.id # userinfo5左邊全部顯示 # select * from userinfo5 right join department5 on userinfo5.part_id = department5.id # department5右邊全部顯示 select * from userinfo5 innder join department5 on userinfo5.part_id = department5.id 將出現null時一行隱藏 select * from department5 left join userinfo5 on userinfo5.part_id = department5.id left join userinfo6 on userinfo5.part_id = department5.id select score.sid, student.sid from score left join student on score.student_id = student.sid left join course on score.course_id = course.cid left join class on student.class_id = class.cid left join teacher on course.teacher_id=teacher.tid select count(id) from userinfo5;

先生成兩張表tb11\tb12

            create table tb12(
                id int auto_increment primary key,
                name varchar(32),
                age int
            )engine=innodb default charset=utf8;

as別名不影響數據,只影響表頭

  增1行

insert into tb11(name,age) values(alex,12);

  增多行

insert into tb11(name,age) values(alex,12);

  將一個表的所有數據,復制到另一張表中

insert into tb12(name,age) select name,age from tb11;

其他

  通配符:

  分頁:

排序

分組

作業練習:
http://www.cnblogs.com/wupeiqi/articles/5729934.html
10-15個完成

MySQL-6-語句數據行操作