sql去除重复的几种方法
2024-10-18 11:20:48
所以用这样一句SQL就可以去掉重复项了:
select * from msg group by terminal_id;
SQL中distinct的用法(四种示例分析)
示例1
select distinct name from A
执行后结果如下:
示例2
select distinct name, id from A
执行后结果如下:
实际上是根据“name+id”来去重,distinct同时作用在了name和id上,这种方式Access和SQL Server同时支持。
示例3:统计
select count(distinct name) from A; --表中name去重后的数目, SQL Server支持,而Access不支持
select count(distinct name, id) from A; --SQL Server和Access都不支持
示例4
select id, distinct name from A; --会提示错误,因为distinct必须放在开头
其他
distinct语句中select显示的字段只能是distinct指定的字段,其他字段是不可能出现的。例如,假如表A有“备注”列,如果想获取distinc name,以及对应的“备注”字段,想直接通过distinct是不可能实现的。
最新文章
- Linux系统编程重要细节记录(持续更新中)
- 显示 Sql Server 中所有表或表中行的信息
- linux 多个python版本的切换
- 父类中“this” 指向问题
- 原生JavaScript实现mouseenter
- Chapter15:派生类
- New MVC World
- UiAutomator源码分析之UiAutomatorBridge框架
- Eclipse报错An internal error occurred during: ";J2EE Component Mapping Update";. java.lang.NullPointerException
- python六十四课——高阶函数练习题(一)
- OSI 协议
- 配置tomcat的开发环境
- C#和java之间的一些差异与共性
- c++运算符重载---20
- LeetCode--168--Excel表列名称
- 世界各国货币,C#数字货币计算
- 修改MVC默认的pageBaseType以添加功能
- Node.js 被分叉出一个项目 — Ayo.js,肿么了
- Codechef Observing the Tree
- bzoj 2453: 维护队列
热门文章
- CentOS 7防火墙的关闭与开启
- oracle 游标相关资料
- 20190712_mysql执行sql脚本语句_Failed to open file_error
- 第15.30节 PyQt编程实战:通过eventFilter监视QScrollArea的widget()的Paint消息画出scrollAreaWidgetContents的范围矩形
- 第14.11节 Python中使用BeautifulSoup解析http报文:使用查找方法快速定位内容
- jarvisoj flag在管理员手上
- CSS初识- 选择器 &;背景&; 浮动&; 盒子模型
- PC微信[多开+免扫码+防撤回撤回提示+转存语音+自动收款+远程命令]
- 《Eroico》关卡与操作设计
- 学习笔记:舞蹈链 Dancing Links