遇到一个SQL有关问题,求高手解决

遇到一个SQL问题,求高手解决
如何把数据表,查成这种模式,前面的姓名,卡号,电话只能出现一次,不能重复  
  
姓名   卡号     电话              消费项目    次数

张三    234    1333323         蜡水洗车     1
                                            臭氧消毒      2
                                             
------解决方案--------------------
select 姓名, 卡号, 电话, 消费项目 ,count('次数') 次数
from tb
group by 姓名, 卡号, 电话, 消费项目

------解决方案--------------------
select case when 消费项目 = (select min(消费项目) from tb where 姓名 = t.姓名) then 姓名 else '' end 姓名,
       case when 消费项目 = (select min(消费项目) from tb where 姓名 = t.姓名) then 卡号 else '' end 卡号,
       case when 消费项目 = (select min(消费项目) from tb where 姓名 = t.姓名) then 电话 else '' end 电话,
       消费项目, 次数
from tb t

------解决方案--------------------
use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
姓名 char(5),
卡号 int,
电话 char(9),
消费项目 char(9),
次数 int
)
go
--插入测试数据
insert into tb select '张三',234,'1333323','蜡水洗车',1
union all select  '张三',234,'1333323','臭氧消毒',2
union all select  '张三',234,'1333323','消毒',2
union all select '李四',237,'1553323','蜡水洗车',3
union all select  '李四',237,'1553323','臭氧消毒',2
go
--代码实现

;with t as(select idd=row_number()over(partition by 姓名 order by 次数),* from tb)
select 姓名=case when idd=1 then rtrim(姓名) else '' end
,卡号=case when idd=1 then rtrim(卡号) else '' end
,电话=case when idd=1 then rtrim(电话) else '' end
,消费项目,次数
from t

/*测试结果

姓名 卡号 电话 消费项目 次数
--------------------------------------
李四 237 1553323 臭氧消毒  2
蜡水洗车  3
张三 234 1333323 蜡水洗车  1
臭氧消毒  2
消毒      2

(5 行受影响)
*/

------解决方案--------------------
我靠
20分的帖子都抢的这么猛!~~

------解决方案--------------------
好生猛哦
------解决方案--------------------
该回复于2010-09-29 11:02:25被版主删除
------解决方案--------------------