开发者

select distinct first row from database

开发者 https://www.devze.com 2023-03-14 07:58 出处:网络
number| time 421112233444 | 1304010250 421112233444 | 1304272979 421001122333 | 1303563263 421112233444 | 1300217115
number      | time 

421112233444 | 1304010250

421112233444 | 1304272979

421001122333 | 1303563263

421112233444 | 1300217115

421001122333 | 1303649310

i need to return unique first row with lowest number from second row, like this:

421112233444 | 1300217115

421001122333 | 1303563263

any idea?

i try SELECT ph.number, mo.time from (select distinct(number) from table) ph, table mo where mo.number = ph.number;

but it returns both uniques:

421112233444 | 1304010250

421112233444 | 1304272979

421001122333 | 1303563263

421112233444 | 13开发者_Go百科00217115

421001122333 | 1303649310


You can use the GROUP BY to do this:

SELECT number, MIN(time)
FROM table
GROUP BY number
ORDER BY number DESC
LIMIT 2


SELECT ph.number, min(mo.time) from (select distinct(number) from table) ph, table mo group by ph.number
0

精彩评论

暂无评论...
验证码 换一张
取 消