例如:
select cNo,cColor,sum(qty) as qty from table1 group by cNo,cColor
这个结果中没有唯一值的列。
用select identityCol,cNo,cColor,sum(qty) as qty from table1 group by cNo,cColor时,提示不能有group by子句;如果用 identity(int,1,1)生成唯一列时得用into子句,也不想用此方法。
有无其他的办法呢?
select cNo,cColor,sum(qty) as qty from table1 group by cNo,cColor
这个结果中没有唯一值的列。
用select identityCol,cNo,cColor,sum(qty) as qty from table1 group by cNo,cColor时,提示不能有group by子句;如果用 identity(int,1,1)生成唯一列时得用into子句,也不想用此方法。
有无其他的办法呢?
select identityCol,cNo,cColor,sum(qty) as qty into #t from table1 group by cNo,cColorselect * from #t这样也不会在你的数据库中留下实际的数据表。别的方法---------------不会!!!!!!期待高手!
因为你group by中是两个字段值,所以这两个字段共同组成一个唯一值。没有单独的唯一字段,若要单独的就不能在group by中放置两个字段。在用select identityCol,cNo,cColor,sum(qty) as qty from table1 group by cNo,cColor时,中,你当然不能加上identity了
可以强制得到一个唯一字段,但会丢失数据。使
得结果不完整。ccolor在前的那个组字段可以返回,其它的就只能是丢弃了