1

I need to order by this SQl statement to get the Item count for <%# Eval("ICount") %>

The problem is i don't know how to "ORDER BY" this one

SQL:

SELECT DATEPART(DAY,BLG_DATE) as DDay,
      datename(month,BLG_DATE) as DMonth,
       DATEPART(YEAR,BLG_DATE) as DYear,COUNT(BLG_DATE) as ICount
FROM [BLG] 
INNER JOIN [ACC] 
ON [BLG].ACC_ID=[ACC].ACC_ID 
WHERE [BLG].ACC_ID='1'and [BLG].BLG_DATE LIKE '%2013%' ORDER BY --????

ASP.NET:

<asp:Repeater ID="childRep" runat="server">
     <ItemTemplate>
          <li><a href="blog.aspx?month=<%# Eval("DMonth") %>"><em><%# Eval("DDay") %></em><%# Eval("DMonth") %><span><%# Eval("ICount") %></span></a></li>  
     </ItemTemplate>
 </asp:Repeater>

I need the column DMonth,DDay,DYear, and ICount to fill the Repeater

Note: I only have table BLG(BLG_ID,ACC_ID,BLG_DATE) and ACC(ACC_ID,ACC_USER,ACC_PASS)

4

2 回答 2

4

is this one you are looking for?

SELECT DATEPART(DAY,BLG_DATE) as DDay,
      datename(month,BLG_DATE) as DMonth,
       DATEPART(YEAR,BLG_DATE) as DYear ,
       (SELECT COUNT(*) 
         FROM [BLG] 
          INNER JOIN [ACC]  ON [BLG].ACC_ID=[ACC].ACC_ID 
         WHERE [BLG].ACC_ID='1'and [BLG].BLG_DATE LIKE '%2013%') AS ICount
FROM [BLG] 
INNER JOIN [ACC] 
ON [BLG].ACC_ID=[ACC].ACC_ID 
WHERE [BLG].ACC_ID='1'and [BLG].BLG_DATE LIKE '%2013%'
于 2013-08-02T07:22:16.253 回答
2

Try this one -

SELECT t.DDay, t.DMonth, t.DYear, cnt = COUNT(1)
FROM (
    SELECT
          DDay = DATEPART(DAY, BLG_DATE) 
        , DMonth = DATENAME(MONTH, BLG_DATE) 
        , DYear = DATEPART(YEAR, BLG_DATE) 
    FROM [BLG] b
    JOIN [ACC] a ON b.ACC_ID = a.ACC_ID
    WHERE b.ACC_ID = '1'
        AND b.BLG_DATE LIKE '%2013%'
) t
GROUP BY t.DDay, t.DMonth, t.DYear
ORDER BY 
      DYear
    , DMonth
    , DDay
于 2013-08-02T07:21:47.877 回答