查詢全部內容sql
SELECT * from table;
查詢前10條數據數據庫
按照ColumnName這一列升序排列的前100條c#
SELECT top 10 * FROM Table ORDER BY ColumnName ASC;
查詢後10條code
按照ColumnName這一列降序排列的前10條排序
SELECT top 3 * FROM Table ORDER BY ColumnName DESC;
嵌套select語句,既有條件又有排序string
先取出最大的3個數據,而後再進行篩選table
SELECT * FROM ( SELECT TOP 3 * FROM Table ORDER BY ColumnName DESC ) WHERE ColumnName > 2
先進行篩選,再進行排序class
SELECT TOP 3 * FROM (SELECT * FROM Table WHERE ColumnName >2) ORDER BY ColumnName DESC
C#對數據庫返回的DataTable進行排序select
DataTable dt = new DataTable(); dt.Columns.Add("ProductID", typeof(string)); dt.Columns.Add("CreateTimeStamp", typeof(string));
dr = dt.NewRow();
.....
dt.Rows.Add(dr); dt.DefaultView.Sort = "CreateTimeStamp DESC";
}
CreateTimeStamp 是列名,ASC/DESC 升序/降序排列。