高级查询
模糊查询 ---like
定义:查询时,字段中的内容并不一定与查询内容完全匹配,只要字段中含有这些内容
select id,name from work where name like 'a'
模糊查询---between
定义:把某一字段中内容在特定范围内的记录查询出来
select id,name from work where id between 1 and 2
模糊查询---in
定义:把某一字段中内容与所列出的查询内容列表匹配的记录查询出来
select id,name from work where id in (1,2)
聚合函数
sum
select sum (id)as 总和 from work
avg
select avg (id) as 平均 from work
max
select max (id) as 最大 from work
min
select min (id) as 最大 from work
count
select count (id) as 最大 from work
分组查询:group by (平均id)
select avg (id) as 平均 from work group by id
多连接查询---分类
内联结:inner join
SELECT Students.SName, Score.CourseID, Score.Score
FROM Students,Score
WHERE Students.SCode = Score.StudentID
多表查询---三表联结
SELECT
S.SName AS 姓名, CS.CourseName AS 课程, C.Score AS 成绩
FROM Students AS S
INNER JOIN Score AS C ON (S.SCode = C.StudentID)
INNER JOIN Course AS CS ON (CS.CourseID = C.CourseID
多表联结查询---左外联结
SELECT Titles.Title_id, Titles.Title, Publishers.Pub_name
FROM titles
RIGHT OUTER JOIN Publishers
ON Titles.Pub_id = Publishers.Pub_id
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE 更多精彩关注: http://www.gopedu.com/
模糊查询 ---like
定义:查询时,字段中的内容并不一定与查询内容完全匹配,只要字段中含有这些内容
select id,name from work where name like 'a'
模糊查询---between
定义:把某一字段中内容在特定范围内的记录查询出来
select id,name from work where id between 1 and 2
模糊查询---in
定义:把某一字段中内容与所列出的查询内容列表匹配的记录查询出来
select id,name from work where id in (1,2)
聚合函数
sum
select sum (id)as 总和 from work
avg
select avg (id) as 平均 from work
max
select max (id) as 最大 from work
min
select min (id) as 最大 from work
count
select count (id) as 最大 from work
分组查询:group by (平均id)
select avg (id) as 平均 from work group by id
多连接查询---分类
内联结:inner join
SELECT Students.SName, Score.CourseID, Score.Score
FROM Students,Score
WHERE Students.SCode = Score.StudentID
多表查询---三表联结
SELECT
S.SName AS 姓名, CS.CourseName AS 课程, C.Score AS 成绩
FROM Students AS S
INNER JOIN Score AS C ON (S.SCode = C.StudentID)
INNER JOIN Course AS CS ON (CS.CourseID = C.CourseID
多表联结查询---左外联结
SELECT S.SName,C.CourseID,C.Score
FROM StudentsAS S
LEFT JOIN ScoreAS C
ON C.StudentID= S.SCode
SELECT Titles.Title_id, Titles.Title, Publishers.Pub_name
FROM titles
RIGHT OUTER JOIN Publishers
ON Titles.Pub_id = Publishers.Pub_id
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE 更多精彩关注: http://www.gopedu.com/