首页 新闻 会员 周边

sql中三个表查询去除重复问题

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-04-22 11:00

create table cate
(
 id int primary key,
 cateName nvarchar(50),
 countScore float,--分数
 ctime smalldatetime default(getdate())--添加该类别时间
)
create table kplan
(
 id int identity(1,1) primary key,
 username nvarchar(30) foreign key references Users(username),
 cid int  foreign key references cate(id),--类别id外键
 context text,--内容
 ptime nvarchar(12),--几月份(上中下旬)计划时间
 publishTime smalldatetime default(getdate()),--填写时间
 sIf nvarchar(10) default('未审核')--已审核、未审核
)
create table ksuccess
(
 id int identity(1,1) primary key,
 username nvarchar(30) foreign key references Users(username),
 cid int  foreign key references cate(id),--类别id外键
 score float,--得分
 ptime nvarchar(12)--几月份(上中下旬)计划时间
)
我写的语句是:
select c.id as id,c.cateName as cateName,k.context as context,c.countScore as countScore,s.score as score from ((kplan as k inner join cate as c on k.cid=c.id) inner join ksuccess as s on s.cid=k.cid) where k.username='张存江' and k.ptime='2011年4月上旬' and s.ptime='2011年4月上旬' and k.sIf='已审核'
得到的结果:
id       cateName                         context  countScore  score
1 原有系统常规维护工作是基础工作   aa              40             40
1 原有系统常规维护工作是基础工作   aa              40              10
2 新项目建设计划完成工作               aa              40               40
2 新项目建设计划完成工作               aa              40               11
3 其他工作                                    aa              10                5
3 其他工作                                    aa               10               10
4 学习                                          aa               10                5
4 学习                                          aa                10              10
怎么去除每行的重复项呢?请教高手?

问题补充: 请高手指教!
aspneteye的主页 aspneteye | 初学一级 | 园豆:4
提问于:2011-04-01 16:49
< >
分享
所有回答(3)
0

DISTINCT 去掉重复的值。

奋斗张 | 园豆:514 (小虾三级) | 2011-04-01 16:55
添加上distinct后报错。text和distinct不能用。context是text类型。
支持(0) 反对(0) aspneteye | 园豆:4 (初学一级) | 2011-04-01 17:06
0

group by

彭汉生 | 园豆:1233 (小虾三级) | 2011-04-01 18:07
0

select distinct(c.cateName) as cateName,c.id as id,k.context as context,c.countScore as countScore,s.score as score from ((kplan as k inner join cate as c on k.cid=c.id) inner join ksuccess as s on s.cid=k.cid) where k.username='张存江' and k.ptime='2011年4月上旬' and s.ptime='2011年4月上旬' and k.sIf='已审核'

wlz0815 | 园豆:587 (小虾三级) | 2011-04-02 14:28
distinct(c.cateName) as cateName这样写也是报错
支持(0) 反对(0) aspneteye | 园豆:4 (初学一级) | 2011-04-22 10:17
错误信息贴出来。
支持(0) 反对(0) wlz0815 | 园豆:587 (小虾三级) | 2011-04-25 10:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册