MySQL——3

复习

1.Mysql是什么?mysql

2.增删改查sql

       insert into xx(name) values(''),()session

       insert into xx(name) select name from tab1;ide

3.自增学习

       1.起始值spa

       2.步长code

              -sessionblog

              -global排序

4.惟一索引索引

       1.unique

       2.联合惟一索引

5.排序

       order by id desc(asc)

6.通配符

select from tb1 where name like 'a%'('a_')

7.分页

       limit

8.链接

       select name from tb1 left join tb2 on tb1.id = tb2.id

9.删

       delete from tb1;

       truncate table tb1;

       drop table tb1;

10.分组

       select count(id) from tb1 group by name having count(id)>10;

11.筛选条件

       in

       not in

       between and

       !=

       and

       or

12.外键的变种

       foreign+unique

学习内容

1.Navicat

              -建立表

              -新建查询

              ...

              -转储SQL文件

                     备份:数据表结构+数据

                            mysqldump -u root db1 > db1.sql -p

                     备份:数据表结构

                            mysqldump -u root -d db1 > db1.sql -p

                    

                     执行文件:

                            create detabase db5;

                            mysqldump -u root db5 > db1.sql -p

       2.临时表

              select sid from (SELECT * from score where num > 60) as B

代码区

-- SELECT * from score where num>60;

-- SELECT teacher_id,count(cname) from course GROUP BY teacher_id;

-- SELECT * from course
-- left JOIN teacher on course.teacher_id=teacher.tid;

-- SELECT * from student
-- left join class on student.class_id=class.cid;

-- SELECT count(sid) as number,gender  from student GROUP BY gender
-- select sid from (SELECT * from score where num > 60) as B 

-- SELECT
--     B.student_id,
--     student.sname,
--     B.ccc 
-- FROM
--     ( SELECT student_id, avg( num ) AS ccc FROM score GROUP BY student_id HAVING ccc > 60 ) AS B
--     LEFT JOIN student ON B.student_id = student.sid;
     
-- SELECT
--     T1.student_id,
--     T1.sname,
--     count(1 ),
--     sum( T1.num ) 
-- FROM
--     (
-- SELECT
--     score.student_id,
--     score.course_id,
--     score.num,
--     student.sname
-- FROM
--     score
--     LEFT JOIN student ON score.student_id = student.sid 
--     ) AS T1 
-- GROUP BY
--     student_id

-- SELECT
--     student.sid,
--     student.sname 
-- FROM
--     student 
-- WHERE
--     student.sid NOT IN (
-- SELECT
--     B.student_id 
-- FROM
--     (
-- SELECT
--     teacher.tid,
--     teacher.tname,
--     course.cid,
--     score.student_id,
--     student.sname 
-- FROM
--     teacher
--     LEFT JOIN course ON teacher.tid = course.teacher_id
--     LEFT JOIN score ON course.cid = score.course_id
--     LEFT JOIN student ON score.student_id = student.sid 
-- WHERE
--     tname = '李平老师' 
--     ) AS B 
-- GROUP BY
--     B.student_id 
--     )

-- SELECT
--     student.sid,
--     student.sname 
-- FROM
--     student 
-- WHERE
--     student.sid IN (
-- SELECT
--     A.id 
-- FROM
--     (
-- SELECT
--     score.student_id AS id,
--     num AS num_s 
-- FROM
--     score
--     LEFT JOIN course ON score.course_id = course.cid 
-- WHERE
--     course.cname IN ( '生物' ) 
--     ) AS A
--     LEFT JOIN (
-- SELECT
--     score.student_id AS id,
--     num AS num_w 
-- FROM
--     score
--     LEFT JOIN course ON score.course_id = course.cid 
-- WHERE
--     course.cname IN ( '物理' ) 
--     ) AS B ON A.id = B.id 
-- WHERE
--     A.num_s > B.num_w 
--     )
View Code
相关文章
相关标签/搜索