33问答网
所有问题
用sql语句实现在同一张表中找到1个字段相同,另1个字段不同的记录
问题补充: 比如表A中 字段1 字段2 2 43 3 65 2 68 1 92 2 55 1 100 用sql语句实现查询,查询出表 1 92、100 2 43、68、55 3 65 这样结果
举报该问题
推荐答案 2019-08-31
如果是sql
server
2005以下,可以用如下方式来实现
select
t.col1,
stuff((select
'、'+
convert(varchar(10),t1.col2)
from
A
t1
where
t1.col1=
t.col1
for
xml
path('')),1,1,'')
as
col2
from
A
t
group
by
t.col1
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://33.wendadaohang.com/zd/WRB50hPP0Pc45W4dcd.html
相似回答
用sql语句实现在同一张表中找到1个字段相同,另1个字段不同的记录
答:
select distinct x.字段一,x.字段二 from a as x,a as Y where x.字段一=y.字段一 and x.字段二!=y.字段二 其中,x和y是a表的别称,这个原来是用来查询至少选修两门课程的学生,我改成了这样,也就意味着查询结果可能有多个,因为万一有三个,他们之间就是两两不
相同的,
也符合这个条件 ...
用sql语句实现在同一张表中找到1个字段相同,另1个字段不同的记录
答:
如果是
sql
server 2005以下,可以用如下方式来实现 select t.col1,stuff((select '、'+ convert(varchar(10),t1.col2)from A t1 where t1.col1= t.col1 for xml path(''))
,1,1,
'') as col2 from A t group by t.col1
用sql语句实现在同一张表中找到1个字段相同,另1个字段不同的记录
答:
oracle数据库中后者可以用wmsys.wm_concat
实现,
具体
sql
如下:select
字段1,
wmsys.wm_concat(字段2)from 表 group by 字段1
大家正在搜