下面的代码从MySQL表中查询“timestamp”类型字段,称为“time”。
$contest = "SELECT SUM(points) AS total, COUNT(points) AS total2, loginid, comment
FROM contest
WHERE loginid = '$idn'";
编辑:我想对所有行的点数求和。但是,我想显示最近时间戳的注释。我如何在1个查询中执行此操作?
答案 0 :(得分:2)
SELECT points, comment, timestamp
FROM contest
WHERE loginid = '$idn'
ORDER BY timestamp DESC
LIMIT 1
答案 1 :(得分:0)
根据您编辑的帖子:
$contest = "SELECT SUM(points) AS total, COUNT(points) AS total2
FROM contest
WHERE loginid = '$idn'
GROUP BY time DESC
LIMIT 1";