以数据库字段分组显示数据的sql语句(详细介绍)
时间:2024-01-29 07:39:49
<?php
$dsn = "mysql:host=localhost;dbname=group";
$db = new PDO($dsn, 'root', '');
$db->exec('set names utf8');
$sql = "select conf_id from `group` group by conf_id";
//$pre = $db->prepare($sql);
//$result_arr = array();
$pre = $db->query($sql);
$result_arr = $pre->fetchAll(PDO::FETCH_ASSOC);
//print_r ($result_arr);
foreach ($result_arr as $v)
{
echo $v[conf_id]."<br>";
$vv = $v[conf_id];
$re = array();
$sql1 = "select * from `group` where conf_id = '$v[conf_id]' order by time";
$sql2 = "select * from `group` where conf_id = '$v[conf_id]' order by time DESC";
$rs1 = $db->query($sql1);
$rs2 = $db->query($sql2);
$re1[$vv] = $rs1->fetchAll(PDO::FETCH_ASSOC);
$re2[$vv] = $rs2->fetchAll(PDO::FETCH_ASSOC);
print_r($re1[$vv][0]);
print_r($re2[$vv][0]);
}
标签:数据库,字段分组,sql语句
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现手机销售管理系统
2023-01-16 00:02:04
![](https://img.aspxhome.com/file/2023/3/81713_0s.jpg)
使用Python编写类UNIX系统的命令行工具的教程
2023-08-24 05:03:02
vue中Axios添加拦截器刷新token的实现方法
2024-05-13 09:07:41
手把手教你将Vim改装成一个IDE编程环境(图文) 吴垠
2023-09-09 22:40:43
![](https://img.aspxhome.com/file/2023/2/132402_0s.png)
MySQL5.7更改密码时出现ERROR 1054 (42S22)的解决方法
2024-01-23 12:12:47
![](https://img.aspxhome.com/file/2023/6/121276_0s.jpg)
如何使用Django(python)实现android的服务器端
2022-09-25 01:06:43
![](https://img.aspxhome.com/file/2023/2/111962_0s.png)
sqlserver四舍五入使用round函数及cast和convert函数
2024-01-21 18:20:53
Python读取及保存mat文件的注意事项说明
2022-01-10 13:25:54
![](https://img.aspxhome.com/file/2023/1/120261_0s.png)
Python中lambda的用法及其与def的区别解析
2021-09-22 13:59:03
Python reversed函数及使用方法解析
2023-01-24 16:10:53
utf8_unicode_ci与utf8_general_ci的区别
2010-03-03 15:54:00
PHP实现向关联数组指定的Key之前插入元素的方法
2023-07-14 08:41:33
浅谈Python面向对象编程oop思想心得
2021-10-25 16:45:29
Python+matplotlib实现堆叠图的绘制
2023-07-21 17:38:35
![](https://img.aspxhome.com/file/2023/2/61182_0s.png)
vue使用ElementUI时导航栏默认展开功能的实现
2024-05-09 15:18:14
简单了解Python中的几种函数
2023-09-30 06:11:55
返回页面顶部top按钮通过锚点实现(自写)
2024-04-10 10:47:23
![](https://img.aspxhome.com/file/2023/4/136934_0s.jpg)
Pygame的程序开始示例代码
2021-12-20 19:45:01
![](https://img.aspxhome.com/file/2023/8/99538_0s.png)
Go Map并发冲突预防与解决
2024-02-19 00:25:24
mybatis统计每条SQL的执行时间的方法示例
2024-01-28 12:54:43