SQL/ SEARCHING 按ClassId查询
Posted gamecenter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL/ SEARCHING 按ClassId查询相关的知识,希望对你有一定的参考价值。
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查询的主要内容,如果未能解决你的问题,请参考以下文章