select name from
(
select distinct name from tb where subject = '语文' and > 80
union all
select distinct name from tb where subject = '数学' and > 80
) t
group by name having count(*) = 2
select name from
(
select distinct name from tb where subject = '语文' and >= 80
union all
select distinct name from tb where subject = '数学' and >= 80
) t
group by name having count(*) = 2
(
select distinct name from tb where subject = '语文' and > 80
union all
select distinct name from tb where subject = '数学' and > 80
) t
group by name having count(*) = 2
select name from
(
select distinct name from tb where subject = '语文' and >= 80
union all
select distinct name from tb where subject = '数学' and >= 80
) t
group by name having count(*) = 2
解决方案 »
- 为什么用T-sql插入数据始终报错?
- SQL日期转换08 21 2011 6:53PM,如何变成2011-08-21 18:53:00
- 帮忙复杂sql语句
- 将int转化成左边用0填充的4位字符串?
- 取Min值,不好意思再问一次
- SQL安装完成后(个人开发版),可以打开企业管理器,但是使用查询分析器无法连接到服务器,也无法找到本机,那位高人帮忙下,谢谢!
- 我有一个三十万条的数据表,怎样才能快速删除其中大部分数据
- 这样的视图应该怎样设计?
- asp 为什么调用存储过程总是失败阿???
- 请问,那位有sql server 存储过程方面的电子书吗?或是网上哪里有
- 如何查询表info的A字段中相同值超过10条记录的 记录数
- 用户 'sa' 登录失败?
select distinct name from tablename where id in (select id from tb where subject='语文' and >80)
and id in (select id from tb where subject='数学' and >80)
and id in (select id from tb where subject='数学' and >80)
> 80) and a.subject ='数学' and (isnull(,0) > 80)
> 80) and a.subject ='数学' and (isnull(,0) > 80)
select name
from tb
where subject='语文' or subject='数学' and >=80
group by name
having count(*)=2
insert into #tb(id,name,subject, )
select '1','小王','语文','80'
union all select '2','小王','语文','85'
union all select '3','小李','数学','82'
union all select '4','小李','数学','70'select name
from #tb
where subject='语文' or subject='数学' and >=80
group by name
having count(*)=2 /*
小王
*/
(
select id from Table_1 where subject in('语文','数学') and > 80
)不知道是不是你想要的结果?
FROM _table mt1
WHERE mt1.subject = '语文'
AND mt1. > 80
AND mt1.name IN (
SELECT mt2.name
FROM _table mt2
WHERE mt2. > 80
AND mt2.subject = '数学')
select name from
(
select *
,case when subject='语文' and >=80 then 1 else 0 end as yw
,case when subject='数学' and >=80 then 1 else 0 end as sx from tt
) n
group by name
having SUM(yw) + SUM(sx) =2
id name subject
1 小王 语文 80
2 小王 语文 85
3 小李 数学 82
4 小李 数学 70 要求:查询到语文和数学成绩都大于80分的人名。select distinct name from 表名
where sno in(
select sno from 表名
where >80 and
subject in(语文)
)
and sno in (
select sno from 表名
where >80 and
subject in(数学)
)
in(select 人名 from 表名 here >80 and subject in(语文))
and sno in ( select 人名 from 表名 where >80 and subject in(数学))