--测试代码
use
SQL_Test
go
create table ttime(
bh varchar(200) not null,
sj datetime,
num int not null
)
insert into ttime
select '2009111601','2009-11-16 15:01:46','1'
union all
select '2009111601','2009-11-16 15:02:46','2'
union all
select '2009111601','2009-11-16 15:03:46','3'
union all
select '2009111601','2009-11-16 15:04:46','4'
union all
select '2009111602','2009-11-16 15:05:46','5'
union all
select '2009111602','2009-11-16 15:06:46','6'--查询
??
--结果
4
6如何能够将4,6输出出来呢?我用如下代码能够输出,但怎么改都改不出4,62009-11-16 15:04:46
2009-11-16 15:06:46
$result=mysql_query("SELECT max(sj) as sj FROM ttime GROUP BY bh");
while($row=mysql_fetch_array($result)){
echo $row["sj"]."<br />";
}
我用下面这段代码只能输出1,5 $result=mysql_query("SELECT num, max(sj) as sj FROM ttime GROUP BY bh");
while($row=mysql_fetch_array($result)){
echo $row["num"]."<br />";
}
use
SQL_Test
go
create table ttime(
bh varchar(200) not null,
sj datetime,
num int not null
)
insert into ttime
select '2009111601','2009-11-16 15:01:46','1'
union all
select '2009111601','2009-11-16 15:02:46','2'
union all
select '2009111601','2009-11-16 15:03:46','3'
union all
select '2009111601','2009-11-16 15:04:46','4'
union all
select '2009111602','2009-11-16 15:05:46','5'
union all
select '2009111602','2009-11-16 15:06:46','6'--查询
??
--结果
4
6如何能够将4,6输出出来呢?我用如下代码能够输出,但怎么改都改不出4,62009-11-16 15:04:46
2009-11-16 15:06:46
$result=mysql_query("SELECT max(sj) as sj FROM ttime GROUP BY bh");
while($row=mysql_fetch_array($result)){
echo $row["sj"]."<br />";
}
我用下面这段代码只能输出1,5 $result=mysql_query("SELECT num, max(sj) as sj FROM ttime GROUP BY bh");
while($row=mysql_fetch_array($result)){
echo $row["num"]."<br />";
}
from ttime
group by bh
直接用刚才的语句只能够输出no,yes