返回信息流表结构如下,非常的简单
CREATE TABLE dbo.test
(
fdcCol1 varchar(255) NULL,
fdcCol2 varchar(255) NULL,
fdiId numeric(10,0) IDENTITY
)
LOCK DATAROWS
测试数据:
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc1', 'msc2' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc1', 'msc2' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc2', 'msc3' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc3', 'msc1' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc2', 'msc2' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc1', 'msc3' )
INSERT INTO dbo.test ( fdcCol1, fdcCol2 ) VALUES ( 'msc5', 'msc2' )
问题: 写出一条sql,统计出fdcCol2中各个值的不重复的fdcCol1,并且fdcCol1不等于fdcCol2的个数.
如上面的数据得出的结果是:
msc1 1
msc2 2 <------- 它的fdcCol1有msc1,msc1,msc2,msc5, 去掉重复的,还有msc2 则是2.
msc3 2
这是一条镜像帖。来源:北邮人论坛 / soft-design / #27493同步于 2008/6/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖
[坑] SQL --- 接受各种BT
atian25
2008/6/27镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
标准答案
C+A
select fdcCol2 ,count(distinct fdcCol1) from test where fdcCol1!=fdcCol2 group by fdcCol2
楼下欢迎各种BT答案