SELECT * FROM Student
UPDATE Student SET StudentName=‘王波‘ WHERE StudentNo=‘Y21003011‘
UPDATE Student SET StudentName=‘王波‘ WHERE StudentNo=‘Y21003011‘
--模糊查询:查询学生表中姓’冯‘的学生记录
--
--‘%‘:匹配0-n个任意字符
--‘_‘匹配单个字符
--‘[]‘匹配区间内的值:如[13]
--‘[^]‘匹配区间内不包含的值
SELECT * FROM Student WHERE StudentName LIKE ‘王_‘
SELECT * FROM Result WHERE SubjectId LIKE ‘[1-9]‘
SELECT * FROM Result WHERE SubjectId LIKE ‘[^1-3]‘
--查询空的数据行
SELECT * FROM Student WHERE Email=‘‘
--查询区间内数据:BETWEEN AND
SELECT * FROM Result WHERE SubjectId BETWEEN 1 AND 10
SELECT * FROM Result WHERE SubjectId BETWEEN 1 AND 10
--查询与列所匹配值相同的数据:IN
SELECT * FROM Student WHERE Address IN (‘新疆乌鲁木齐‘,‘北京市海淀区五道口北大青鸟IT职业技术学院‘,‘黑龙江哈尔滨‘)
SELECT * FROM Student WHERE Address IN (‘新疆乌鲁木齐‘,‘北京市海淀区五道口北大青鸟IT职业技术学院‘,‘黑龙江哈尔滨‘)
--平均值
SELECT AVG(StudentResult) AS ‘平均成绩‘ FROM Result
SELECT AVG(StudentResult) AS ‘平均成绩‘ FROM Result
--最大值,最小值
SELECT MAX(StudentResult) AS ‘最高成绩‘ FROM Result
SELECT MIN(StudentResult) AS ‘最低成绩‘ FROM Result
SELECT MAX(StudentResult) AS ‘最高成绩‘ FROM Result
SELECT MIN(StudentResult) AS ‘最低成绩‘ FROM Result
--统计记录数:COUNT(*)和COUNT(1)的区别
SELECT COUNT(StudentNo) AS ‘记录数‘ FROM Result
SELECT COUNT(StudentNo) AS ‘记录数‘ FROM Result
count(*)和count(1)的区别:
从执行计划来看,count(1)和count(*)的效果是一样的。 但是在表做过分析之后,count(1)会比count(*)的用时少些(1w以内数据量),不过差不了多少。 如果count(1)是聚索引,id,那肯定是count(1)快。但是差的很小的。 因为count(*),自动会优化指定到那一个字段。所以没必要去count(1),用count(*),sql会帮你完成优化的 因此:count(1)和count(*)基本没有差别! count(*)包括了所有的列,相当于行数,在统计结果的时候,不会忽略列值为NULL count(1)包括了忽略所有列,用1代表代码行,在统计结果的时候,不会忽略列值为NULL