(Help)inner join连接多表查询出现重复数据 如何解决啊?

ntwqy_2008 2009-01-16 02:58:51
如题。
使用distinct后数据是1条,如果不使用则出现6条,拜膜高手...
...全文
1303 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ny-6000 2009-01-16
  • 打赏
  • 举报
回复
just like layer two
jy00251278 2009-01-16
  • 打赏
  • 举报
回复
sql 里用count读数
C# 里用tables[i].rows.count
cow8063 2009-01-16
  • 打赏
  • 举报
回复
那你使用distinct不就行了?

重复是来自一个表还是多个表?

left join?
bjwtufv 2009-01-16
  • 打赏
  • 举报
回复
mark
cyz9977 2009-01-16
  • 打赏
  • 举报
回复
在使用join時候的注意點:
如果只要使用join的表中某個或幾個字段,就不要join整個表!!!!


select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp
inner join (select distinct CourseID from OLTR_StudyStudentRCourse) as rc on etp.CourseID=rc.CourseID
inner join (select distinct CourseID from OLTR_StudySubjectRCourse) as src on etp.CourseID=src.CourseID
inner join (select distinct subjectid from OLTR_StudyProjectRSubject) as rs on src.SubjectID=rs.SubjectID
inner join (select distinct ProjectID from OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1
and (StartTime <= getdate() and getdate() <= Endtime )
where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID
from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'


lizhengnan 2009-01-16
  • 打赏
  • 举报
回复
distinct不会影响count.

你不用COUNT不行吗.

用DATATABLE.ROWS.COUNT来显示记录的条数.
ntwqy_2008 2009-01-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lizhengnan 的回复:]
什么意思呀,不明白.
你加上distinct不就得了吗
[/Quote]
我使用的asp.net2.0分页控件,如果使用了distinct数据显示在gv中是1条,但是地下的总记录数显示是6,
而且还有一个问题。如下:

select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp
inner join OLTR_StudyStudentRCourse as rc on etp.CourseID=rc.CourseID
inner join OLTR_StudySubjectRCourse as src on etp.CourseID=src.CourseID
inner join OLTR_StudyProjectRSubject as rs on src.SubjectID=rs.SubjectID
inner join OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1
and (StartTime <= getdate() and getdate() <= Endtime )
where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID
from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'

我想要得到count()的值.我想得到1 ,却出来6 ,如何是好a 加distinct也不行!!!!????????
lizhengnan 2009-01-16
  • 打赏
  • 举报
回复
什么意思呀,不明白.
你加上distinct不就得了吗

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧