假如有以下数据:字段: 姓名 科目 学号
以下为数据: 张继萍、 数学 001
张继萍 语文 001
李东坡 语文 002
李东坡 数学 002
李东坡 英语 002
薛佳 数学 003
我想求出以下数据:
至少包含姓名为张继萍所参加的科目的学生的学号即: 002,001
以下为数据: 张继萍、 数学 001
张继萍 语文 001
李东坡 语文 002
李东坡 数学 002
李东坡 英语 002
薛佳 数学 003
我想求出以下数据:
至少包含姓名为张继萍所参加的科目的学生的学号即: 002,001
select distinct 学号 from (select distinct count(姓名),学号 from table where 科目 exist (select 科目 from table where 姓名="张继萍")) group by 学号 having count(姓名)=(select count(科目) from table where 姓名="张继萍")
2楼方法恐怕不行吧
from((select 学号,wmsys.wm_concat(学科) a1 from (select * from table order by 姓名,学科) group by 学号) a,
(select wmsys.wm_concat(学科) b1 from (select * from table order by 姓名,学科) where 姓名='张继萍') b)
where length(a.a1)-length(replace(a.a1,b.b1,'')=length(b.b1);