نمایش سطرهای دلخواه


گاهی نیاز داریم که سطرهای مشخص از یک جدول را نمایش دهیم مثلا در یک لیست سطر ۲و ۵
را نمایش دهیم. برای این کار روشهای متفاوتی وجود دارد که من در اینجا یک روش ساده
و کاربردی را ارائه میکنم. ابتدا یک جدول ایجاد می کنیم تا چند مثال را روی آن
انجام دهیم . این جدول کد کارمند، نام و حقوق کارمندان را شامل میشود.

CREATE TABLE Employee
 (
     EID int unique,
     EmployeeName varchar(100),
     Salary money
 );

بعد از ایجاد جدول اطلاعات زیر را وارد جدول می کنیم

 insert into Employee values(120,'Amir Reza Jaberi',25000.00)
 insert into Employee values(121,'Reza Faraji',1025000.00)
 insert into Employee values(129,'Khalil Hajavi',30000.00)
 insert into Employee values(135,'Farhad Tarhan',22000.00)
 insert into Employee values(009,'Mina Abasie',2522000.00)
 insert into Employee values(007,'Korosh',122000.00)
 insert into Employee values(123,'Mahyar',50000.00)

حال میخواهیم سومین کارمندی که بیشترین حقوق را میگیرد نمایش دهیم : برای این کار
از تابع ROW_NUMBER استفاده میکنیم و لیست را بر اساس حقوق مرتب میکنیم و در انتها
در یک شرط شماره سطر را فیلتر می نماییم.

SELECT *
 FROM(
     SELECT ROW_NUMBER() OVER (ORDER BY Salary DESC) AS SrNo,
             EId,EmployeeName, Salary
     FROM
         Employee
     )    AS EMPLOYEE
 WHERE
     SrNo=3
نحوه نمایش محدوده رکوردها :
   SELECT *
 FROM(
     SELECT ROW_NUMBER() OVER (ORDER BY Salary DESC) AS SrNo,
             EId,EmployeeName, Salary
     FROM
         Employee     )    AS EMPLOYEE
 WHERE
     SrNo between 3 and 5

این نوشته در SQL Server ارسال شده است. افزودن پیوند یکتا به علاقه‌مندی‌ها.

71 دیدگاه دربارهٔ «نمایش سطرهای دلخواه»

  1. فرهاد می‌گوید:

    با سلام .
    امیر جان خوشحالم که شروع به نوشتن کردی.یاد ان سایتی افتادم که سال ۸۰ نوشته بودی و خیلی از دوستان از انتشار آن پشیمانت کردن.
    بازم ممنونم که تجربیات خودتو به اشتراک گذاشتی.
    ارادتمتد فرهاد

  2. Bobs می‌گوید:

    Thanks for shranig. What a pleasure to read!

  3. Brysen می‌گوید:

    Home run! Great sluggnig with that answer!

  4. Cynthia Mitch می‌گوید:

    Do you mind if I published this blog post on my web page? I would give you credit and a link back to your webpage. Thank you, and don’t hesitate to let me know here!

  5. Donald McFadyen می‌گوید:

    Thanks for the suggestions you are giving on this site. Another thing I would like to say is that getting hold of duplicates of your credit score in order to inspect accuracy of each and every detail could be the first measures you have to accomplish in fixing credit. You are looking to clean up your credit file from dangerous details mistakes that spoil your credit score.

  6. Duncan Hunter می‌گوید:

    I like the helpful information you supply to your articles. I’ll bookmark your weblog and take a look at once more here regularly. I’m quite certain I will be informed a lot of new stuff right here! Best of luck for the next!

  7. zlewozmywaki می‌گوید:

    The subsequent time I learn a blog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my choice to read, but I actually thought youd have one thing fascinating to say. All I hear is a bunch of whining about something that you could fix if you happen to werent too busy looking for attention.

  8. body lotion می‌گوید:

    Hi there may I use some of the information here in this post if I provide a link back to your site?

  9. zlewozmywaki می‌گوید:

    I have not checked in here for a while because I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend

  10. motel Rzeszów می‌گوید:

    Succesfull article. Thumb up for the author ;D. I’ll let know about this site friends I am sure that they should also like it. I am sure I’ll check this page in the future. See you

  11. امیررضا می‌گوید:

    Thank you

  12. click می‌گوید:

    Have you considered including several social bookmarking links to these blogs. At the very least for facebook.

  13. xrumer service 123 o می‌گوید:

    Hello there, I found your web site via Google while searching for a related topic, your site came up, it looks good. I have bookmarked it in my google bookmarks.

  14. Do you have a spam problem on this website; I also am a blogger, and I was curious about your situation; we have developed some nice practices and we are looking to swap strategies with other folks, be sure to shoot me an e-mail if interested.

  15. choroby przelyku vw می‌گوید:

    Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your weblog? My blog site is in the exact same niche as yours and my users would really benefit from some of the information you provide here. Please let me know if this okay with you. Thanks!

  16. Zyprexa می‌گوید:

    Hiya very nice site!! Man .. Beautiful .. Wonderful .. I will bookmark your blog and take the feeds additionally…I am satisfied to seek out a lot of helpful information here within the publish, we’d like work out extra techniques on this regard, thanks for sharing. . . . . .

  17. Abe Unglesbee می‌گوید:

    I simply want to tell you that I am just very new to blogging and site-building and certainly enjoyed this web-site. More than likely I’m going to bookmark your website . You really come with exceptional articles and reviews. Thanks a bunch for revealing your web-site.

  18. kindiukof می‌گوید:

    I would like to thank you for the efforts you have put in writing this web site. I am hoping the same high-grade web site post from you in the upcoming also. Actually your creative writing abilities has encouraged me to get my own site now. Actually the blogging is spreading its wings fast. Your write up is a good example of it.

  19. Adell Liederbach می‌گوید:

    I have read several good stuff here. Certainly price bookmarking for revisiting. I surprise how so much effort you set to create this sort of magnificent informative website.

  20. Reyna می‌گوید:

    You Sir/Madam are the enemy of confusion eevrywerhe!

  21. Sudaryono می‌گوید:

    Such a deep aneswr! GD&RVVF

  22. Kathlyn Mulvihill می‌گوید:

    I really like reading an article that will make people think. Also, thank you for allowing me to comment!

  23. free videos pantyhose می‌گوید:

    I think your site is pretty great, i found it from a good collegue of mine from USA

  24. Harold Zanghi می‌گوید:

    very good publish, i definitely love this web site, keep on it

  25. sports betting می‌گوید:

    amirreza.jaberi.eu gives me so much fun, thanks

    [url=http://topbettingtips.tumblr.com]http://topbettingtips.tumblr.com[/url]

  26. free nokia unlock می‌گوید:

    Can’t stop reading amirreza.jaberi.eu keep up good work!
    [url=http://www.youtube.com/watch?v=8SZ28YK8cTc]Unlock Nokia N96[/url]
    [url=http://www.youtube.com/watch?v=AvTE9jDv0xY]Unlock Nokia E75[/url]
    [url=http://www.youtube.com/watch?v=9IbPl4okHLI]Unlock Nokia Lumia 710[/url]

  27. bet on mma می‌گوید:

    amirreza.jaberi.eu gives me so much joy, thanks

    [url=http://cold-soul.tumblr.com]ufc betting[/url]

  28. Shad Walk می‌گوید:

    Fantastic web site I found info pretty informative. I come here the many time and they normally deliver excellent material!

دیدگاه‌ها غیرفعال هستند.