SQL筛选两个字段同时满足条件的结果

原始表
现在有一张student表,包含三个字段:s_id,c_id,s_score:
在这里插入图片描述

目的1:如果只保留得到s_id为01,s_score为80的结果

输入语句:

select * from score where case when s_id =01 and s_score =80 then 0 else 1 end=
0;

结果:
在这里插入图片描述

目的2:筛选除同时满足s_id为01,s_score为80以外的所有数据
输入语句:

select * from score where case when s_id =01 and s_score =80 then 0 else 1 end=
1;

输出结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yilulvxing/article/details/88721734