Just use TOP 5
:
SELECT TOP 5 [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews]
FROM [ArticlesTBL]
WHERE ([ArticlePublished] = @ArticlePublished)
ORDER BY [ArticleViews] DESC
문제
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