내 포럼에 대한 모든 카테고리를 표시하는 목록을 작성하려고합니다. ID와 함께 카운트와 함께이 카테고리에 연결된 스레드 수를 나타내는 카테고리 이름을 표시합니다.SQL 카운터 및 리턴 기가 결과를 두 배로 만듭니다.
완벽하게 작동하지만 결과가 두 번 인쇄됩니다.
이
다음은 SQLSELECT categories.category_name, threads.thread_category_id, COUNT(*)
AS 'threadCount' FROM threads
INNER JOIN categories ON categories.category_id = threads.thread_category_id
GROUP BY categories.category_name, threads.thread_category_id
인 결과를
입니다 그리고 당신이 볼 수 있듯이, 그것은 어떤이 should't, 두 번 같은 일을 인쇄합니다.
편집 : 여기에 ASP가 있습니다.
1) SQL이 잘못 아마 당신이 있습니다 (:
<asp:Repeater ID="categories" runat="server">
<HeaderTemplate>
<table id="kategorier" cellspacing="0">
<tr>
<td class="head">Name</td>
<td class="head" style="width:70px">Number of Threads</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="item"><a href="Kategori.aspx?id=<%# Eval("thread_category_id") %>"><%# Eval("category_name") %> - ID: <%# Eval("thread_category_id")%></a></td>
<td class="item" style="text-align:right"><%# Eval("threadCount") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
, 중복 행 재곡이 있습니까? –
질의 실행/빌더에서 실행할 때 중복되지 않습니다. –
문제가 쿼리에 있지 않으므로 ASP 코드에 있습니다. –