作者bobju (宝贝猪)
看板Database
标题Re: [SQL ] 改如何下指令显示栏位的值
时间Fri Nov 28 08:09:10 2008
我想到较好的方式是写程式捞资料出来整理. 直接下sql查的话虽有想到方式,
但只能勉强配合这个特例输出, 并不通用.
假设用PHP:
//1. 先建立资料库连线, 选择 table1
...
//2. 接着进行捞资料, 建立关联:
$last = '';
$sql="select * from table1 order by email,type";
$rows=mysql_query($sql);
foreach($row=mysql_fetch_assoc($rows)){
if( $last != $row['email'] ){
$type_list['email']=$row['type'];
$last = $row['email'];
}
else{
$type_list['email'].=','.$row['type'];
}
}
//3. 最後输出:
foreach($type_list as $email => $lst){
printf("%s %s\n",$email,$lst);
}
※ 引述《ginzu (茹)》之铭言:
: TABLE内容如下:
: 该如何下SQL 指令显示type栏位的值
: (主要是想知道哪些email存在两种或是三种类别)
: email type
: [email protected] E
: [email protected] P
: [email protected] P
: [email protected] H
: [email protected] H
: [email protected] E
: [email protected] P
: [email protected] H
: [email protected] E
: [email protected] E
: 变成
: email type
: [email protected] E,P
: [email protected] P
: [email protected] P,H,E
: [email protected] H
: [email protected] H,E
: [email protected] E
: [email protected] P
: 谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.74.110.209
※ 编辑: bobju 来自: 211.74.110.209 (11/28 08:33)