日期:2014-05-18  浏览次数:20427 次

求一SQL语句,关于同一名称但价格不等
求一SQL语句,即在数据库里,想把同一名称但单价不同的列出来,这个SQL怎么写呢?

------解决方案--------------------
参考这个:
http://community.csdn.net/Expert/TopicView3.asp?id=5431297
------解决方案--------------------
Select A.* From
表 A
Where Exists(Select * From 表 Where 名称 = A.名称 And 单价 != A.单价)
------解决方案--------------------
Select A.* From
表 A
Where Exists(Select * From 表 Where 名称 = A.名称 And 单价 != A.单价)

------------
這個就可以撒
------解决方案--------------------
Create Table TEST(名称 Varchar(10), 单价 Int)
Insert TEST Select 'A ', 10
Union All Select 'A ', 20
Union All Select 'B ', 50
Union All Select 'C ', 20
Union All Select 'C ', 30
Union All Select 'D ', 80
GO
--方法一
Select A.* From
TEST A
Where Exists(Select * From TEST Where 名称 = A.名称 And 单价 != A.单价)
--方法二
Select A.* From
TEST A
Where 名称 In (Select 名称 From TEST Group By 名称 Having Count(*) > 1)
GO
Drop Table TEST
--Result
/*
名称 单价
A 10
A 20
C 20
C 30
*/