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

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
博客园 - 聂微东
Y
Y Combinator Blog
罗磊的独立博客
博客园_首页
小众软件
小众软件
有赞技术团队
有赞技术团队
爱范儿
爱范儿
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏

博客园 - 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
----------------