sqlserver in查询年龄和城市案例

37work

--in 查询
--in 操作符,允许您在where子句中规定多个值
--01 查询年龄为22,28的学生信息 
select * from st where age in(22,28);
--1.1 
select * from st where age in(22,28,35);
--1.2 查询城市在上海,北京,济南的学生信息
select * from st where city in('上海','北京','济南');
--分组查询按照年龄分组
select age from st group by age;
-- 分组各年龄学生人数汇总
select age as 年龄,count(*) as 人数 from st  group by age;

 --update 
 --update st set city='上海' where id<=3;
 --update st set city='北京' where id>=4 and id<=6;
 --update st set city='济南' where id>=7 and id<=9;
 update st set city='济宁' where id>=8 and id<=10;

 --2 根据城市分组查询学生信息.不同城市的学生信息
 select city as 城市 from st  group by city;
 --2.1 汇总人数
 select city as 城市,count(*) as 人数汇总 from st group by city;

效果

 城市

 

age 年龄

  

猜你喜欢

转载自blog.csdn.net/chenggong9527/article/details/123522842