تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيفيه استخدام ال Any
#1
كاتب الموضوع : AhmedEssawy

في المثال التالي سوف يتم الاستعلام عن كل الاسماء من جدول

Employee

بشرط ان يكون راتب الفرد اصغر من متوسط الرواتب

averageSalary

الموجوده في

جدول

job


كود :
[align=left][color=#990000]1[/color][color=black]>[/color][FONT=Courier New]
[color=#990000]2[/color]> create [color=black]table employee([/color]
[color=#990000]3[/color][color=black]> ID int,[/color]
[color=#990000]4[/color][color=black]> name nvarchar ([/color][color=#990000]10[/color][color=black]),[/color]
[color=#990000]5[/color]> salary int [color=black])[/color]
[color=#990000]6[/color][color=black]> GO[/color]
[color=#990000]1[/color][color=black]>[/color]
[color=#990000]2[/color]> create [color=black]table job([/color]
[color=#990000]3[/color][color=black]> ID int,[/color]
[color=#990000]4[/color][color=black]> title nvarchar ([/color][color=#990000]10[/color][color=black]),[/color]
[color=#990000]5[/color]> averageSalary int[color=black])[/color]
[color=#990000]6[/color][color=black]> GO[/color][/FONT]
[color=#990000]1[/color][color=black]>[/color][FONT=Courier New]
[color=#990000]2[/color][color=black]>[/color]
[color=#990000]3[/color]> select * from [color=black]employee;[/color]
[color=#990000]4[/color][color=black]> GO[/color]
[color=black]ID name salary[/color]
[color=black]----------- ---------- -----------[/color]
[color=#990000]1 [/color][color=black]Jason [/color][color=#990000]1234[/color]
[color=#990000]2 [/color][color=black]Robert [/color][color=#990000]4321[/color]
[color=#990000]3 [/color][color=black]Celia [/color][color=#990000]5432[/color]
[color=#990000]4 [/color][color=black]Linda [/color][color=#990000]3456[/color]
[color=#990000]5 [/color][color=black]David [/color][color=#990000]7654[/color]
[color=#990000]6 [/color][color=black]James [/color][color=#990000]4567[/color]
[color=#990000]7 [/color][color=black]Alison [/color][color=#990000]8744[/color]
[color=#990000]8 [/color][color=black]Chris [/color][color=#990000]9875[/color]
[color=#990000]9 [/color][color=black]Mary [/color][color=#990000]2345[/color]

[color=black]([/color][color=#990000]9 [/color][color=black]rows affected)[/color]
[color=#990000]1[/color]> select * from [color=black]job;[/color]
[color=#990000]2[/color][color=black]> GO[/color]
[color=black]ID title averageSalary[/color]
[color=black]----------- ---------- -------------[/color]
[color=#990000]1 [/color][color=black]Developer [/color][color=#990000]3000[/color]
[color=#990000]2 [/color][color=black]Tester [/color][color=#990000]4000[/color]
[color=#990000]3 [/color][color=black]Designer [/color][color=#990000]5000[/color]
[color=#990000]4 [/color][color=black]Programmer [/color][color=#990000]6000[/color]

[color=black]([/color][color=#990000]4 [/color][color=black]rows affected)[/color][/FONT]
[color=#990000]1[/color][color=black]>[/color][FONT=Courier New]
[color=#990000]2[/color][color=black]>[/color]
[color=#990000]3[/color]> -- If [color=black]your subquery returns a scalar value, you can use a comparison operator,[/color]
[color=#990000]4[/color][color=black]>[/color]
[color=#990000]5[/color]> SELECT [color=black]e.ID,e.name[/color]
[color=#990000]6[/color]> FROM [color=black]Employee e[/color]
[color=#990000]7[/color]> WHERE e.salary > ANY (SELECT averageSalary FROM [color=black]job j)[/color]
[color=#990000]8[/color][color=black]> GO[/color]
[color=black]ID name[/color]
[color=black]----------- ----------[/color]
[color=#990000]2 [/color][color=black]Robert[/color]
[color=#990000]3 [/color][color=black]Celia[/color]
[color=#990000]4 [/color][color=black]Linda[/color]
[color=#990000]5 [/color][color=black]David[/color]
[color=#990000]6 [/color][color=black]James[/color]
[color=#990000]7 [/color][color=black]Alison[/color]
[color=#990000]8 [/color][color=black]Chris[/color]

[color=black]([/color][color=#990000]7 [/color][color=black]rows affected)[/color][/FONT][/align]
}}}}
تم الشكر بواسطة:


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم