我需要帮助来实现在结果的最后10行中我有多少状态= 1?
如果在最后10行中有3个状态,我需要输出3个。
SELECT * FROM results WHERE $position='$text' and make='$make' and status='1'
答案 0 :(得分:3)
您需要使用子查询来获取最后10行,然后计算该子集中有多少status = 1
。
SELECT COUNT(*) AS count
FROM (SELECT status
FROM results
WHERE $position = '$text' AND make = '$make'
ORDER BY id DESC
LIMIT 10) AS last10
WHERE status = '1'