且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sybase SQL基于具有ID的多列选择不同

更新时间:2023-02-02 22:42:06

也许您必须使用汇总函数 max min 作为列ID。

Maybe you have to use aggregate function max or min for column ID. It will return only one ID for grouped columns.

select max(Id), type, breed 
from animals
group by type, breed 

编辑:

其他实现方法:

具有汇总功能

select id, type, breed  
from animals 
group by type, breed  
having id = max(Id)

具有子查询和汇总子查询

select id, type, breed 
from animals a1
group by type, breed 
having id = (
               select max(id)
               from animals a2
               where a2.type = a1.type
               and   a2.breed = a1.breed
            )