sql查询............... [英] sql query ...............

查看:69
本文介绍了sql查询...............的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个表人,需要查询那些personName谁是



1.工资最高



2.cityCode是12



3.年龄是32







假设 - 有3人名字为RAM。



和3名字sunil



和3个人姓名rahul ....





我只需要那些记录谁包含最高工资



表示ram最高工资,sunil最高工资和rahul最高工资

解决方案

如果您要求三个查询....

 选择  top  1 )PersonName 来自 person 订单 薪资 Desc    -   最高薪水 
选择 PersonName 来自 person 其中 citycode = 12 - - CityCode = 12
选择 PersonName 来自其中​​年龄= 32 - 年龄= 32





如果您要求获得城市代码12和32岁时薪水最高的人的姓名然后查询是:

 选择  top  1 )PersonName 来自 person 其中 citycode = 12 年龄= 32  order   by  salary  Desc  

...



如果这不是您所需要的..使用改善问题小部件....



根据您的要求,您可以使用Damian S编写的multiQuery或

 选择 p1 .PersonName 来自 person p1 
inner join 选择最大(工资) maxsalary 来自 person 其中 Citycode = 12 age = 32)p2 on p1.salary = p2.maxsalary 其中​​ p1.CityCode = 12 p1.age = 32





但如果你想要最高工资组你可以使用的人:

 选择 PersonName,max(Salary) as  Salary 来自 person 其中​​ age = 32  Citycode = 12   by  PersonName 


这将需要一个多部分查询。您需要一个部分来查找给定城市代码和年龄的最高工资,还有一部分要返回名称...这样:



 选择 personName 
来自 person
其中 salary =(选择 max(薪水)来自 person 其中 citycode = 12 age = 32
citycode = 12
age = 32


试试这个



 选择 PersonName,MAX(薪水)
来自 PERSON
wh ere cityCode = 12
年龄= 32
group by PersonName


I a table "person" and need a query for those personName who's

1.salary is maximum

2.cityCode is 12

3. age is 32



suppose- there are 3 person with name RAM .

AND 3 with name sunil

and 3 person with name rahul....


and i need the only those record who contain the maximum salary

means ram with maximum salary , sunil with maximum salary and rahul with maximum salary

解决方案

If you are asking for three queries....

Select top(1) PersonName from person Order by Salary Desc -- maximum salary
Select PersonName from person where citycode=12  -- CityCode=12
select PersonName from Person where age=32  -- age=32



if you are asking for name of the person earning highest salary in citycode 12 and age 32. Then the query is:

Select top(1) PersonName from person where citycode=12 and age=32 order by salary Desc

...

if this is not what u required.. use Improve Question widget....

As per your requirement u can use the multiQuery written by Damian S or

Select p1.PersonName from person p1 
inner join (Select Max(salary) as maxsalary from person where Citycode=12 and age=32)p2 on p1.salary=p2.maxsalary Where p1.CityCode=12 and p1.age=32



But if you want max salary grouped on person you can use:

Select PersonName, max(Salary) as Salary from person where age=32 and Citycode=12 Group by PersonName


This will require a multipart query. You need one part to find the maximum salary for a given citycode and age, and one part to return the name... like this:

select personName 
from person 
where salary = (select max(salary) from person where citycode = 12 and age = 32) 
and citycode = 12 
and age = 32


Try this

select  PersonName, MAX(Salary)
from    PERSON
where   cityCode = 12
and Age = 32
group by PersonName


这篇关于sql查询...............的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆