惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
腾讯CDC
Y
Y Combinator Blog
L
LangChain Blog
B
Blog
U
Unit 42
P
Proofpoint News Feed
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
WordPress大学
WordPress大学
月光博客
月光博客
Vercel News
Vercel News
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗

博客园 - Lee-hp

SQL:去掉重复行,只保留第一行 游标(转3) 游标(转2) 游标(转) Sql:取每个分类的前10条数据 水晶报表参考资料 xml操作 页面信息抓取(二) 页面信息抓取 在GridView中绑定Radio 引用js脚本的奇怪问题 读博 好好工作,好好学习 游标使用——获取每个分类的前10条数据 Url传递中文 SQL触发器--插入时判断数据是否已存在 程序开发和参考资料 SQLServer - 标识列自增 锻炼你的专注力
sql:去掉重复行
Lee-hp · 2007-05-10 · via 博客园 - Lee-hp

表结构和数据如下:
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
----------------