小编San*_*eep的帖子

选择一个不同的行

我有一个 MySQL 表:

o_id | Salesperson |   fax   | Pincode  
1      Sandy         2110271   12011
2      Sandy         2452356   24523
3      Ricky         1023564   45510
Run Code Online (Sandbox Code Playgroud)

我需要得到以下结果:

Salesperson |   fax   | Pincode  
Sandy         2452356   24523
Ricky         1023564   45510
Run Code Online (Sandbox Code Playgroud)

(注意:我不需要显示 o_id 列)

我试过了:

select distinct salesperson,faxno,pin 
from OPPORTUNITY
Run Code Online (Sandbox Code Playgroud)

和:

select salesperson,faxno,pincode 
from OPPORTUNITY 
Group By (salesperson)
Run Code Online (Sandbox Code Playgroud)

...但我仍然得到:

select distinct salesperson,faxno,pin 
from OPPORTUNITY
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多网络上的场景,但仍然无法达到预期的结果。

是否有任何属性或函数会给出“桑迪” - 其o_id最大值。

例子:

Select distinct sales, faxno, pincode 
from opportunity where o_id= max(o_id)
Run Code Online (Sandbox Code Playgroud)

虽然上面的代码不起作用,但类似的东西可以帮助吗?

mysql greatest-n-per-group

2
推荐指数
1
解决办法
1260
查看次数

标签 统计

greatest-n-per-group ×1

mysql ×1