首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求教一查询语句!救急高手们!该怎么解决

2012-01-08 
求教一查询语句!!!救急啊!!高手们!!表Anamescota1b1c1d2e2实现成:a1d2问题2:实现成:ab1ac1bc1de2[解决办法

求教一查询语句!!!救急啊!!高手们!!
表A       name       scot
              a             1
              b             1
              c             1
              d             2
              e             2

实现成:     a         1
                    d         2

问题2:   实现成:     a   b   1
                                    a   c   1
                                    b   c   1
                                    d   e   2

[解决办法]
1. select min(name),scot from A group by scot
[解决办法]
select
t.*
from
表 t
where
not exists(select 1 from 表 where name <t.name and scot=t.scot)

select
a.name,b.name,a.scot
from
表 a,表 b
where
a.scot=b.scot and a.name <b.name
order by
a.scot.a.name,b.name
[解决办法]
表A name scot
a 1
b 1
c 1
d 2
e 2

实现成: a 1
d 2

select min(name) name,scot from tb group by scot
[解决办法]
--------------例子--------
create table A(name varchar(10),scot int)
insert A
select 'a ',1 union all
select 'b ',1 union all
select 'c ',1 union all
select 'd ',2 union all
select 'e ',2

select min(name),scot from a group by scot

select
a.name,b.name,a.scot
from
a,a b
where
a.scot=b.scot and a.name <b.name
order by
a.scot,a.name,b.name

热点排行
Bad Request.