1

我有一个 MySQL 数据库,其中有一堆列,但重要的两个是“power”和“td”(时差)列。

我需要在每一行中将“power”除以“td”,然后在设定的时间段内将所有行相加。

我知道WHERE year(time) = year(getdate()) AND month(time) = month(getdate()) AND day(time) = day(getdate()) ORDER BY (time) DESC只选择适用于今天的行的部分。

如何将每一行的“power”列除以“td”列,然后在 PHP 中将所有这些行加在一起?

4

2 回答 2

0

可能是这样的?

Select SUM(power/td) from sometable where time = GetDate() order by time DESC;
于 2012-09-22T21:08:46.787 回答
0
select sum(power/td)
from mytable
WHERE year(time) = year(getdate()) 
AND month(time) = month(getdate()) 
AND day(time) = day(getdate())

您不需要 ,ORDER BY因为您正在聚合行。

于 2012-09-22T21:08:49.177 回答