码迷,mamicode.com
首页 > 数据库 > 详细

SQL/ SEARCHING 按ClassId查询

时间:2019-08-17 12:21:40      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:where   sql   HERE   inf   rom   insert   tab   arc   ble   

 ST_NAME  || ST_ID  || CLASS_ID  || CLASS_INFO   
 ---------------------------------------------  
  MARK     ||   1    ||     100   || MATH  
  YEN      ||   2    ||     101   || CHEM  
  SALLY    ||   3    ||     100   || MATH  
  SARA     ||   4    ||     103   || HIST  
正确解法:

create table test(st_name varchar, st_id int, class_id int, class_info int);

insert into test values(‘MARK‘, 1, 100, ‘MATH‘);
insert into test values(‘YEN‘, 2, 101, ‘CHEM‘);
insert into test values(‘MARK‘, 3, 100, ‘MATH‘);
insert into test values(‘MARK‘, 4, 103, ‘HOST‘);

SELECT (MAX(counter) > 1) as sameClass FROM (SELECT COUNT(st_id) counter FROM test 
WHERE ST_ID IN (1,2) GROUP BY class_info);

SELECT (MAX(counter) > 1) as sameClass FROM (SELECT COUNT(st_id) counter FROM test 
WHERE ST_ID IN (1,2,3) GROUP BY class_info);

SQL/ SEARCHING 按ClassId查询

标签:where   sql   HERE   inf   rom   insert   tab   arc   ble   

原文地址:https://www.cnblogs.com/gamecenter/p/11368015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!