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

推荐订阅源

F
Fortinet All Blogs
罗磊的独立博客
IT之家
IT之家
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
博客园 - Franky
博客园 - 聂微东
博客园_首页
爱范儿
爱范儿
量子位
博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
Martin Fowler
Martin Fowler
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
Vercel News
Vercel News
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
Engineering at Meta
Engineering at Meta

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