以数据库字段分组显示数据的sql语句(详细介绍)

2023年 4月 22日 65.5k 0

复制代码 代码如下: ?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 = arra

复制代码 代码如下:<?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]);}

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论