row-number

How To Project a Line Number Into Linq Query Results

眉间皱痕 提交于 2019-11-26 07:27:31
问题 How can I project the row number onto the linq query result set. Instead of say: field1, field2, field3 field1, field2, field3 I would like: 1, field1, field2, field3 2, field1, field2, field3 Here is my attempt at this: public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count) { Guid guid = new Guid(gameId); using (PPGEntities entities = new PPGEntities()) { int i = 1; var query = from s in entities.Scores where s.Game.Id == guid orderby s.PlayerScore descending select new

MySQL - Get row number on select

喜你入骨 提交于 2019-11-25 22:25:49
问题 Can I run a select statement and get the row number if the items are sorted? I have a table like this: mysql> describe orders; +-------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------------+------+-----+---------+----------------+ | orderID | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | itemID | bigint(20) unsigned | NO | | NULL | | +-------------+---------------------+------+----

ROW_NUMBER() in MySQL

南笙酒味 提交于 2019-11-25 22:13:09
问题 Is there a nice way in MySQL to replicate the SQL Server function ROW_NUMBER() ? For example: SELECT col1, col2, ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY col3 DESC) AS intRow FROM Table1 Then I could, for example, add a condition to limit intRow to 1 to get a single row with the highest col3 for each (col1, col2) pair. 回答1: I want the row with the single highest col3 for each (col1, col2) pair. That's a groupwise maximum, one of the most commonly-asked SQL questions (since it seems