Auto generated Numbers in SQL Query
create table CountryMaster
(
id int identity(1,1),
cityname varchar(50),
countryname varchar(50)
)
select * from CountryMaster
insert into CountryMaster values('New Delhi','India')
insert into CountryMaster values('Mumbai','India')
insert into CountryMaster values('Kolkata','India')
insert into CountryMaster values('Chennai','India')
insert into CountryMaster values('London','UK')
insert into CountryMaster values('Amsterdam','UK')
insert into CountryMaster values('Southampton','UK')
insert into CountryMaster values('Washington','US')
insert into CountryMaster values('New York','US')
insert into CountryMaster values('Chicago','US')
insert into CountryMaster values('Canberra','Australia')
insert into CountryMaster values('NSW','Australia')
insert into CountryMaster values('Melbourn','Australia')
insert into CountryMaster values('Islamabad','Pakistan')
insert into CountryMaster values('Karachi','Pakistan')
insert into CountryMaster values('Hyderabad','Pakistan')
select id, cityname, countryname,
ROW_NUMBER() OVER (PARTITION BY [countryName] ORDER BY id) AS Seq
from CountryMaster
Result
-------
.............................................
id cityname countryname Seq
.............................................
27 Canberra Australia 1
28 NSW Australia 2
29 Melbourn Australia 3
17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4
30 Islamabad Pakistan 1
31 Karachi Pakistan 2
32 Hyderabad Pakistan 3
21 London UK 1
22 Amsterdam UK 2
23 Southampton UK 3
24 Washington US 1
25 New York US 2
26 Chicago US 3
.............................................
select id, cityname, countryname,
ROW_NUMBER() OVER (ORDER BY id) AS Seq
from CountryMaster
Result
-------
.............................................
id cityname countryname Seq
.............................................
17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4
21 London UK 5
22 Amsterdam UK 6
23 Southampton UK 7
24 Washington US 8
25 New York US 9
26 Chicago US 10
27 Canberra Australia 11
28 NSW Australia 12
29 Melbourn Australia 13
30 Islamabad Pakistan 14
31 Karachi Pakistan 15
32 Hyderabad Pakistan 16
.............................................
select id, cityname, countryname,
ROW_NUMBER() OVER(order by id) AS Seq
from CountryMaster order by cityname
Subscribe to:
Post Comments (Atom)
Thanks, I really appreciate the kind words.This given information very easily understand and easily find query after refer that post.
ReplyDeleteiOS Training in Chennai
Thank you for the nice information you had posted. And from this posts i got some valuable information. Please keep update like this with this site.
ReplyDeleteWeb Designing Training in Chennai
That the provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.our giving articles really impressed for me,because of all information so nice.
ReplyDeleteOracle SQL Training in Chennai
Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.
ReplyDeleteSQL DBA Training in Chennai
This blog is having the general information. Got a creative work and this is very different one. We have to develop our creativity mind. This blog helps for this.
ReplyDeleteThank you for this blog. this is very interesting and useful.
SMO Services Chennai
I simply want to tell you that I’m all new to blogs and truly liked you’re blog site. Very likely I’m likely to bookmark your site .You surely come with remarkable articles. Cheers for sharing your website page.
ReplyDeleteCRO Agency in Chennai
Truely a very good article on how to handle the future technology. After reading your post,thanks for taking the time to discuss this, I feel happy about and I love learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.
ReplyDeleteHadoop training in chennai
Truely a very good article on how to handle the future technology. After reading your post,thanks for taking the time to discuss this, I feel happy about and I love learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.
ReplyDeleteBest Hadoop institue in chennai
Actually i am taking training on SQL. Unfortunately i found this blog and i am expecting more posts from you.
ReplyDeleteHouse Cleaning Services in Mumbai
Excellent .. Amazing .. I will bookmark your blog and take the feeds additionally? I’m satisfied to find so many helpful information here within the put up, we want work out extra strategies in this regard, thanks for sharing..
ReplyDeleteHome Cleaning Services Mumbai
I got lot of informations from your blog.Please keep us informed like this.And thanks for sharing!!!
ReplyDeleteSeo Company in India
Nutra Mini - Can you tell if Weight Loss is paid for? This is a fairly new way for defining that with it. I'm the latest person to fall for the Insta Keto Weight Loss bug. It might hurt to try. I learned the lesson quickly. Weight Loss has also been shown to do the same. This is the scoop. That's a step at a time. Without arguing in respect to, the reason why, I also asked men and women this as it relates to Weight Loss. This is not mentioned here. I got the short end of the stick.
ReplyDeleteProstate 911
Keto Bodytone
Control X Keto
Slim Fast Keto Boost
Solli Pantip
Insta Keto Diet
ReplyDeleteTech Products is not important currently. If that was up to me, yes, although this is not up to me. My way is really stimulating and exciting.
AOL support number
powervolt energy saver
ReplyDeleteI apologize, if this is your first time here. I imagine a site focusing on Tech Products will get you the most bang for your buck and tech Products might seem a bit haphazard at first to you. This will be a cool discovery.
PowerPro Energy Saver
Mosquitron
Buzz B Gone