













表结构和数据如下:
id userid isquoted
1 69355164 0
4 69355164 1
5 69355164 1
6 11D8952A 1
查询要求:userid唯一,isquoted=0优先
结果如下:
1 69355164 0
6 11D8952A 1
费了半天劲,不知道还有没有更好的办法:
-----------查询 :userid唯一,isquoted=0优先------
select id,userid,0 as isquoted from quote_s_info
where isquoted = 0
group by userid ,id
union
select id,userid,1 as isquoted from quote_s_info
where isquoted = 1 and userid not in
(
select userid from quote_s_info where isquoted = 0 group by userid
)
group by userid,id
----------------
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。