MySQL GROUP BY 子句如何表现得像 DISTINCT 子句?
技术百科
WBOY
发布时间:2023-09-08
浏览: 次 当我们在 SELECT 语句中使用 GROUP BY 子句而不使用聚合函数时,它的行为类似于 DISTINCT 子句。例如,我们有下表 -
mysql> Select * from testing; +------+---------+---------+ | id | fname | Lname | +------+---------+---------+ | 200 | Raman | Kumar | | 201 | Sahil | Bhalla | | 202 | Gaurav | NULL | | 203 | Aarav | NULL | | 204 | Harshit | Khurana | | 205 | Rahul | NULL | | 206 | Piyush | Kohli | | 207 | Lovkesh | NULL || 208 | Gaurav | Kumar | | 209 | Raman | Kumar | +------+---------+---------+ 10 rows in set (0.00 sec)
通过在“Lname”列上使用 DISTINCT 子句,MySQL 返回以下结果集。
mysql> select Distinct LNAME from testing; +---------+ | LNAME | +---------+ | Kumar | | Bhalla | | NULL | | Khurana | | Kohli | +---------+ 5 rows in set (0.00 sec)
现在,通过使用 GROUP BY 子句,如下所示,我们可以获得与使用 DISTINCT 获得的结果集相同的结果集 -
mysql> Select LNAME from testing GROUP BY Lname; +---------+ | LNAME | +---------+ | NULL | | Bhalla | | Khurana | | Kohli | | Kumar | +---------+ 5 rows in set (0.04 sec)
我们可以观察到MySQL返回的结果集之间存在差异,使用GROUP BY子句的MySQL查询返回的结果集是排序的,而使用DISTINCT子句的MySQL查询返回的结果集是未排序的。 p>
# 而不
# 我们可以
# 可以获得
# 所示
# 观察到
# 类似于
# 当我们
# select
# mysql
# 子句
# 下表
# Sahil
相关栏目:
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
AI推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
SEO优化<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
技术百科<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
谷歌推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
百度推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
网络营销<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
案例网站<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
精选文章<?muma echo $count; ?>
】
相关推荐
- php485返回数据不完整怎么办_php485数据
- Win11怎么自动隐藏任务栏_Win11全屏显示设
- 如何使用Golang实现微服务事件驱动_使用消息总
- 如何在Golang中实现邮件发送功能_Golang
- 如何在网页无标准表格标签时高效提取结构化数据
- 如何在Golang中编写端到端测试_Golang
- Mac如何开启夜览模式_Mac护眼模式设置与定时
- Win11怎么查看电脑配置_Win11硬件配置详细
- Win11怎么关闭触控板_Win11笔记本禁用触摸
- Win11应用商店下载慢怎么办 Win11更改DN
- c++20的std::format怎么用 比pri
- Win11怎么关闭资讯和兴趣_Windows11任
- Windows10如何更改系统字体大小_Win10
- 如何在 Go 中正确反序列化 XML 多节点数组(
- 如何在Golang中处理数据库事务错误_回滚和日志
- PHP cURL GET请求:正确设置请求头与身份
- php高频调试功能有哪些_php常用调试函数与工具
- 如何在 Windows 11 中使用 AlomWa
- Win10如何卸载自带Edge_Win10彻底卸载
- 如何使用Golang实现Web表单数据绑定_自动映
- LINUX的SELinux是什么_详解LINUX强
- Python文件管理规范_工程实践说明【指导】
- 为什么Go需要go mod文件_Go go mod
- Win11怎么打开注册表_Windows 11注册
- C#如何使用XPathNavigator高效查询X
- 企业SEO优化选择网站建设模板的技巧
- C++中的constexpr和const有什么区别
- Win11怎么设置鼠标宏_Win11鼠标按键自定义
- Python网络超时处理_健壮性设计说明【指导】
- Python网络日志追踪_请求定位解析【教程】
- Python与MongoDB NoSQL开发实战_
- windows如何测试网速_windows系统网络
- Windows 11无法安全删除U盘提示设备正在使
- php在Linux怎么部署_LNMP环境搭建PHP
- LINUX下如何配置VLAN虚拟局域网_在LINU
- Windows10怎样设置家长控制_Windows
- Windows 10怎么把任务栏放在屏幕上方_Wi
- Win11怎么关闭通知消息_屏蔽Windows 1
- 电脑的“网络和共享中心”去哪了_Windows 1
- Windows10如何更改桌面背景_Win10个性
- php做exe支持多线程吗_并发处理实现方式【详解
- c++如何利用doxygen生成开发文档_c++
- c# 在高并发下使用反射发射(Reflection
- Mac的“调度中心”与“空间”怎么用_Mac多桌面
- 如何使用Golang sync.Map实现并发安全
- php打包exe怎么传递参数_命令行参数接收方法【
- Win10怎样卸载DockerDesktop_Wi
- Win11怎么设置夜间模式_Windows11显示
- Windows 11怎么设置默认解压软件_Wind
- ACF 教程:如何正确更新嵌套在多层 Group

| 208 | Gaurav | Kumar |
| 209 | Raman | Kumar |
+------+---------+---------+
10 rows in set (0.00 sec)
QQ客服