-- 查询
-- select * from table_name
select * from score;
-- 查询特定列的数据
-- select 列名1,列名2 from table_name
select user_name,score from score;
-- 比较运算符
-- 查询成绩 大于等于90分
select * from score where score >= 90;
-- 查询成绩不等于100的用户名和成绩
select user_name,score from score where score <> 100;
select user_name,score from score where score != 100;
-- 条件筛选
-- 查询成绩大于等于90姓名等于王五的 and
select * from score where score >= 90 and user_name = '王五';
-- 查询 html成绩大于等于90的和查询sql成绩大于等于67的 or
select * from score where score >= 90 and subject = 'HTML';
select * from score where score >= 67 and subject = 'sql';
select * from score where (score >= 90 and subject = 'HTML') or (score >= 67 and subject = 'sql');
-- 查询用户不是张三的 not
select * from score where user_name != '张三';
select * from score where not user_name != '张三';
-- 查询 成绩80-90分之间的数据
select * from score where score between 80 and 90;
-- 查询成绩80-90之外的数据
select * from score where score not between 80 and 90;
-- 模糊查询
-- % 任意字符
-- 查询姓名以王开头
select * from score where user_name like '王%';
-- 中间带由麻的名字
select * from score where user_name like '%麻%';
-- 名字以三结尾
select * from score where user_name like '%三';
-- 查询名字是x三(张三 李三 王三)
select * from score where user_name like '__三';
select * from score where subject like 's_l';--sql
-- null
-- 查询性别为null的值
select * from score where gender = null; -- 错误写法
select * from score where gender is null;-- 使用is null
-- 查询性别不为null
select * from score where gender is not null;
-- top前几个数据
-- 查询前三条数据
select top 3 * from score;
-- 排序
-- order by
-- 成绩从大到小排列
select * from score order by score desc;-- 按照成绩score 降序 desc
-- 成绩从小到大排列
select * from score order by score asc;
-- 查询分数排名前三的学生
select top 3 * from score order by score desc;
select top 3 * from score order by score asc;