DotNet Solution

  • Home
  • Asp.net
    • Controls
    • DataControl
    • Ajax
  • Web Design
    • Html
    • Css
    • Java Script
  • Sql
    • Queries
    • Function
    • Stored Procedures
  • MVC
    • OverView
    • Create First Application
  • BootStrap
    • Collapse Function

Wednesday, 15 June 2016

Rank Given In Table

  Unknown       23:07       Queries       No comments    

Rank Given in Table in SQL Server
If We Want to Give Indviual Rank And Same Rank to Same data Then Use

Use Of  ROW_NUMBER() Function 
1.This function will assign a unique id to each row returned from the query.
2.RANK gives you the ranking within your ordered partition. Ties are assigned the same rank, with the next ranking(s) skipped. So, if you have 3 items at rank 2, the next rank listed would be ranked 5.


DENSE_RANK()
Trivially, DENSE_RANK() is a rank with no gaps, i.e. it is “dense”. We can write:

Code
Create table-
CREATE TABLE Tbl_CityMaster1
(
Id INT PRIMARY KEY IDENTITY,
CityName nvarchar(20),
C_Id int
)
Data Insertd Then OutPut
OutPut-
Id  CityName   C_Id
1    Allahabad    1   
2    Allahabad   1
3    Allahabad    1   
4    Patna        1   
5    Patna        2   
6    Patna        3   
7    Varanasi    3   
8    Varanasi    3   
9    Varanasi    3   
10    Varanasi    3    

Give Rank 

Query-
SELECT
    Id,CityName,[C_id],
    Row_index = ROW_NUMBER() OVER(PARTITION BY [C_Id] ORDER BY [C_Id]),
    SameRank = DENSE_RANK() OVER (ORDER BY [C_Id])
FROM Tbl_CityMaster

OutPut

Id CityName C_Id RowNo SameRank
1    Allahabad    1    1      1
2    Allahabad    1    2      1
3    Allahabad    1    3      1
4    Patna           1    2      2
5    Patna           2    2      2
6    Patna           3     2      2
7    Varanasi      3     1      3
8    Varanasi      3     2      3
9    Varanasi      3     3      3
10    Varanasi    3    4       3



  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email This BlogThis! Share to X Share to Facebook
Newer Post Older Post Home

0 comments :

Post a Comment

Popular Posts

  • Auto Increment Id in Sql Server
    SQL server identity column values use in table Steps- Firstly Open-> Sql Server Create Table -> First Field Like ID Usually Autoi...
  • (no title)
    SQL SELECT Query The SELECT statement is used to select data from a database. Query SELECT * FROM TABLE NAME. Use this query we get All...
  • Alter Query
    To add a column in a table, use Alter Query the following syntax: ALTER TABLE table_name ADD column_name datatype. To delete a column ...
  • MVC OverView
    I ntroduction The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the v...
  • Rank Given In Table
    Rank Given in Table in SQL Server If We Want to Give Indviual Rank And Same Rank to Same data Then Use Use Of  ROW_NUMBER() Function  ...
  • Javascript Regular Expression Email Validate
    Validate Email using Regular Expression In JavaScript- 1. Create Input type Text box and and onclick cal  checkemail function of Javascr...
  • How To Timer Work in Asp.net
    Using a Timer Control Inside an UpdatePanel Control When the Timer control is included inside an UpdatePanel control, the Timer contro...
  • Get Random Rows in SqlServer
    How To Get  Random  ROWS in  Table  Using Sql Server Step 1-                Open Sql Server and Create Table like in Ex. Ex. Step...
  • Values Enter With SplitFunction in Sql Server
    Basically We Use Split Function Thorugh Commma Sepertaed string value with  Comma  Means One Then more value through split function Enter...
  • Open First Application in MVC
    How To Create First Application in MVC.Follows Some Steps-    STEP 1 . Firstly Go Start menu in Computer And Click on Installed Visual s...

Blog Archive

  • ▼  2016 ( 36 )
    • ►  February ( 1 )
    • ►  March ( 5 )
    • ►  April ( 1 )
    • ▼  June ( 10 )
      • Ajax FilteredTextBox Extender
      • Current Date
      • CSS 3D Transforms
      • Use SQL Server Functions
      • Show Table Data
      • Create Table
      • Rank Given In Table
      • COALESCE function
      • Unicque Row Num and Same Rank in Sql server
      • Table Structure Acces in Database
    • ►  July ( 6 )
    • ►  November ( 8 )
    • ►  December ( 5 )
  • ►  2017 ( 1 )
    • ►  January ( 1 )
Powered by Blogger.

Categories

  • Ajax
  • AllFunction
  • Controls
  • CreateApplication
  • css
  • Function
  • javascript
  • Js
  • over view
  • OverView
  • Queries
  • StoredProcedures

Text Widget

Sample Text

Pages

  • Home

Copyright © DotNet Solution | Powered by Blogger
Design by Vibha Acharya