014 数据库学习笔记--查询

发布时间 2023-06-13 11:41:46作者: sunwugang

常用查询方式:

  1. select * from tablename
  2. select col1,clo2 from tablename where age = 18
  3. select col1,clo2 from tablename where  age >=18 and age<=60
  4. select col1,clo2 from tablename where  age between 18 and 60
  5. select top(100) col1,clo2 from tablename where  age between 18 and 60
  6. select top(100) col1,clo2 from tablename where  age is null
  7. select top(100) col1,clo2 from tablename where  age is not null
  8. select top(50)percent  col1,clo2 from tablename where  age
  9. 。。。。。。
--case when
select top(100) student_id, student_name, 
case 
	when student_age <18 then '未成年:' + CONVERT(varchar(50),student_age)+'岁'
	when student_age>=18 and student_age<100 then '成年人:'+ CONVERT(varchar(50),student_age)+'岁'
	else '100以上高寿老人'+ CONVERT(varchar(50),student_age)+'岁'
end as '是否成年人', 
student_sex
from [dbo].[student] order by student_age desc