【问题标题】:How do I output the top 5 results with the highest value in column ArticleViews [duplicate]如何在 ArticleViews 列中输出具有最高值的前 5 个结果 [重复]
【发布时间】:2014-05-14 14:00:57
【问题描述】:

下面是我的数据源。

<asp:SqlDataSource ID="getbyviews" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectAntiFrack %>" 
SelectCommand="SELECT [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews] 
FROM [ArticlesTBL] 
WHERE ([ArticlePublished] = @ArticlePublished) 
ORDER BY [ArticleViews] DESC">
<SelectParameters>
<asp:Parameter DefaultValue="True" Name="ArticlePublished" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>

有没有办法操纵 select 语句只获取 5 个最高的结果?或者这可以在 C# 中完成吗? 我的数据源稍后将用于填充列表视图。

【问题讨论】:

  • 如果有领带,你可能会得到超过 5 个。您想如何处理关系?

标签: c# sql select


【解决方案1】:

只需使用TOP 5:

SELECT TOP 5 [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews] 
FROM [ArticlesTBL] 
WHERE ([ArticlePublished] = @ArticlePublished) 
ORDER BY [ArticleViews] DESC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多