我有,SELECT DISTINCT (first),second,third FROM table
我想要的不仅是第一个是DISTINCT,第二个是DISTINCT,而第三个没有DISTINCT,我试着这样做。
SELECT DISTINCT (first,second),third FROM table
还有更多东西,但没有用。
答案 0 :(得分:6)
SELECT m.first, m.second, m.third -- and possibly other columns
FROM (
SELECT DISTINCT first, second
FROM mytable
) md
JOIN mytable m
ON m.id =
(
SELECT id
FROM mytable mi
WHERE mi.first = md.first
AND mi.second = md.second
ORDER BY
mi.first, mi.second, mi.third
LIMIT 1
)
在(first, second, third)
上创建一个索引,以便快速工作。
答案 1 :(得分:0)