求SQL语句 - MS-SQL Server / 基础类
TableA
id name math eng chinese
1 aaa 100 99 88
2 bbb 65 60 67
3 ccc 110 99 70
4 ddd 77 89 78
如何求出成绩含有99的学生(尽量不要写每个字段)
SQL code:
select distinct name
from
(
select name,math from TableA
union all
select name,eng from TableA
union all
select name,chinese from TableA
) tt
where math>99
SQL code:
create table #TT
(
id int identity(1,1) primary key,
name nvarchar(50),
math int,
eng int,
chinese int
)
insert into #TT select 'aaa',100,99,88
insert into #TT select 'bbb',65,60,67
insert into #TT select 'ccc',110,99,70
insert into #TT select 'ddd',77,89,78
select distinct name
from
(
select name,math from #TT
union all
select name,eng from #TT
union all
select name,chinese from #TT
) tt
where math=99
name
--------------------------------------------------
aaa
ccc
(2 行受影响)
SQL code:
--------------------------------------------------------------------------
-- Author : h
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
第一句:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm
join jh on ht.htbh=jh.hth
and ht.htbh not like'del%' and ht. ......