How do I output the top 5 results with the highest value in column ArticleViews [duplicate]

StackOverflow https://stackoverflow.com/questions/23656877

  •  22-07-2023
  •  | 
  •  

質問

Below is my data source.

<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>

Is there a way to manipulate the select statement to only grab the 5 highest results? Or can this be done in C#? My datasource will be used later to populate a listview.

役に立ちましたか?

解決

Just use TOP 5:

SELECT TOP 5 [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews] 
FROM [ArticlesTBL] 
WHERE ([ArticlePublished] = @ArticlePublished) 
ORDER BY [ArticleViews] DESC
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top