select 时间 = day(时间), ph值平均= avg(PH值) from DH_TDATA where convert(char(7),时间,120)='2004-11' group by day(时间) order by day(时间)
select convert(char(8),时间,112) as 时间 ,avg(ph) as ph值平均 group by convert(char(8),时间,112)
也可以这样 (比较麻烦!!) select 时间 = day(B.时间), ph值平均= A.sumph/A.num from (select sum(PH值) sumph ,count(*) num DH_TDATA group by 时间) A inner join DH_TDATA B on A.时间=B.时间 where substring(B.时间,1,7)='2004-11'
select convert(char,时间,112) as 时间 ,avg(ph) as ph值平均 from DH_TDATA group by convert(char(8),时间,112) go select 时间,ph值平均 from DH_TDATA order by 时间
时间 = day(时间),
ph值平均= avg(PH值)
from
DH_TDATA
where
convert(char(7),时间,120)='2004-11'
group by
day(时间)
order by
day(时间)
group by convert(char(8),时间,112)
select 时间 = day(B.时间),
ph值平均= A.sumph/A.num
from (select sum(PH值) sumph ,count(*) num DH_TDATA group by 时间) A
inner join DH_TDATA B on A.时间=B.时间
where substring(B.时间,1,7)='2004-11'
from DH_TDATA
group by convert(char(8),时间,112)
go
select 时间,ph值平均
from DH_TDATA
order by 时间