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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
L
LangChain Blog
Jina AI
Jina AI
爱范儿
爱范儿
C
Check Point Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
月光博客
月光博客
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
V
V2EX
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题

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