当前位置:数据库 > SQLServer >>

MSSQL查询2个字段一起重复语句错误~HELP

我要查询inventory表,字段broken与nameid一起重复的记录,构造如下语句,出错,返回',' 附近有语法错误。据说in只能有1列,要用and,求助如何修改~~~~ select * from inventory a where (a.broken,a.nameid) in (select broken,nameid from inventory group by broken,nameid having count(*) > 1)
补充:一楼的语句可以成功执行,但是返回结果nameid没有重复,broken重复的记录也列出了.....
答案:select * from inventory a 
join (select broken,nameid from inventory group by broken,nameid having count(*) > 1) b on a.broken=b.broken and a.nameid=b.nameid
其他:select * from inventory a 
where (a.broken+a.nameid) in (select broken+nameid from inventory group by broken,nameid having count(*) > 1)

上一个:怎样把MSSQL数据库还原到虚拟主机上啊
下一个:一个Mssql数据能不能建多个数据文件?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,