row-number

SQL Server ROW_NUMBER behavior

只谈情不闲聊 提交于 2019-12-24 14:12:52
问题 I have the following query: SELECT * FROM ( SELECT a.TeacherID, a.UniversityID, ROW_NUMBER() OVER (ORDER BY a.TeacherID) AS RowNum FROM SelectAll a LEFT JOIN mp_Ratings r ON a.TeacherID = r.TeacherID GROUP BY a.TeacherID, a.UniversityID ) AS TeacherInfo WHERE RowNum BETWEEN 10 AND 50 and it works fine. Now, If I want to do something like: SELECT * FROM ( SELECT a.TeacherID, a.UniversityID, ROW_NUMBER() OVER (ORDER BY a.TeacherID) AS RowNum FROM SelectAll a LEFT JOIN mp_Ratings r ON a

Ordering the row_number using LinqToSql in asp.net/C#

寵の児 提交于 2019-12-24 05:12:21
问题 I have set of records in a database table lets call it Components Table which is defined as follows. The administrator can disable some of the components using disableflag which is the last column of the table. If a particular component is disabled it should not appear in the gridview of the user. I'm getting the data from the database and presenting through the gridview as shown here, if you observe the SNo values are not in order. The linq query that i'm using to retrieve the data is: var

SQL get ROW_NUMBER and COUNT on every SELECT request

混江龙づ霸主 提交于 2019-12-23 22:51:53
问题 I´m building a grid mechanism where I need to retrieve data from Database the total or records found, retrieving just a range of these records with a row_number in it. I´m using SqlServer for testing, but I need to support that on Oracle and MySql as well. That´s what I´m trying, but I can´t make it work: SELECT * FROM (SELECT ROW_NUMBER() AS RN, COUNT(*) AS TOTALCN, Id, Name, Phone FROM MyTable WHERE Deleted='F') WHERE RN > 100 AND RN < 150; The idea is: MyTable -> number of records: 1000

SQL Server 2012: Conditionally Incrementing a counter user ROW_NUMBER()

跟風遠走 提交于 2019-12-23 12:19:20
问题 I am trying to apply ROW_NUMBER() to increment a counter based on particular conditions. My data looks like this, with the target counter being the Prep column id DSR PrepIndicator Prep -------------------------------------- 1662835 -1 1 1 1662835 14 2 2 1662835 14 2 3 1662835 20 2 4 1667321 -1 1 1 1667321 30 2 2 1667321 14 2 3 1680648 -1 1 1 1680648 14 2 2 1680648 60 1 1 1680648 14 2 2 1680648 14 2 3 1683870 -1 1 1 1683870 12 2 2 1683870 10 2 3 1683870 60 1 1 1683870 7 2 2 Ignoring the

SSRS Row Group + Column Group = RowNumber Issue

别说谁变了你拦得住时间么 提交于 2019-12-23 08:47:38
问题 I'm back with another SSRS question :-) I'm dealing with survey data. I have a procedure that's returning an organization's response counts per question. So my report is defined as Group on Organization for row and Group on answer for columns. Both the number of organizations and answers are variable. That's working as expected. I've tried adding a RowCount next to the organization so that I can show rank, but the fact that each org has one row per question means that I'm getting eight rows

SQL - how to update a column with each row value incremented by 1?

情到浓时终转凉″ 提交于 2019-12-23 04:37:25
问题 For the selected rows in a column, how to update each row sequentially from the beginning to the end, with each row value incremented by 1 (or certain number). I know this can be done in excel in few seconds but I could figure out how to achieve in SQL server. For instance: customer id is NULL now update customer id with every row incremented by 1 (i.e. first row = 1, second row = 2, .....nth row = n) ship-to party customer id 0002018092 NULL 0002008127 NULL 0002000129 NULL 0002031592 NULL

MySQL - Select row number of a record

核能气质少年 提交于 2019-12-21 20:05:06
问题 I have a table in MySQL populated as follows. Now I need to select the row number of a record in its sorted order. For example, the row number of words starting with 'c' should be 4 . Words ===== coffee banana apple cherry blackberry I tried the following query, but I get wrong results. Here dict is the table name and words is the column name. SELECT @rownum:=@rownum + 1 id FROM (SELECT * FROM dict ORDER BY words) d,(SELECT @rownum:=0) r WHERE d.words LIKE CONCAT('c','%') For the above query,

PostgreSQL window function: row_number() over (partition col order by col2)

风流意气都作罢 提交于 2019-12-20 20:20:08
问题 Following result set is derived from a sql query with a few joins and a union. The sql query already groups rows on Date and game. I need a column to describe the number of attempts at a game partitioned by date column. Username Game ID Date johndoe1 Game_1 100 7/22/14 1:52 AM johndoe1 Game_1 100 7/22/14 1:52 AM johndoe1 Game_1 100 7/22/14 1:52 AM johndoe1 Game_1 100 7/22/14 1:52 AM johndoe1 Game_1 121 7/22/14 1:56 AM johndoe1 Game_1 121 7/22/14 1:56 AM johndoe1 Game_1 121 7/22/14 1:56 AM

How to show the maximum number for each combination of customer and product in a specific state in Postgresql?

故事扮演 提交于 2019-12-20 06:26:27
问题 I just begin learning Postgresql recently. I have a table named 'sales': create table sales ( cust varchar(20), prod varchar(20), day integer, month integer, year integer, state char(2), quant integer ) insert into sales values ('Bloom', 'Pepsi', 2, 12, 2001, 'NY', 4232); insert into sales values ('Knuth', 'Bread', 23, 5, 2005, 'PA', 4167); insert into sales values ('Emily', 'Pepsi', 22, 1, 2006, 'CT', 4404); insert into sales values ('Emily', 'Fruits', 11, 1, 2000, 'NJ', 4369); insert into

find start and stop date for contiguous dates in multiple rows

一曲冷凌霜 提交于 2019-12-18 18:38:46
问题 I'm having a bit of trouble displaying correct data from my table. Im not really sure what to search for either. Im not sure min(column) or max(column) will help me here. Lets see if i can explain my problem. My table contains this data: > Code (nvarchar) | DateFrom (datetime) | DateTo (datetime) > ========================================================= > 3006 | 2014-06-18 07:00:00 | 2014-06-18 08:00:00 > 3006 | 2014-06-18 09:00:00 | 2014-06-18 22:00:00 > 1006 | 2014-06-18 07:00:00 | 2014