SQL计算所有行而不是计算单个行我有一个SQL语句,它从数据库中请求数据。SELECT `ID`, `To`, `Poster`, `Content`, `Time`, ifnull(`Aura`,0) as `Aura` FROM (
SELECT * FROM (
SELECT DISTINCT * FROM messages m INNER JOIN
(
SELECT Friend2 as Friend FROM friends WHERE Friend1 = '1'
UNION ALL
SELECT Friend1 as Friend FROM friends WHERE Friend2 = '1'
) friends ON m.Poster = friends.`Friend`
UNION ALL SELECT DISTINCT *, '1' FROM messages where `Poster`='1'
) var LEFT JOIN
(
select `ID` as `AuraID`, `Status` as `AuraStatus`, count(*) as `Aura`
from messages_aura ) aura ON (var.Poster = aura.AuraID AND var.ID = aura.AuraStatus)) finalGROUP BY `ID`, `Poster`ORDER BY `Time` DESC LIMIT 10这是我的messages_aura表格布局。它显示ID,Status和UserID。以下是上述声明的输出。(ID从上面的截图参考Poster下面的以及Status上面的截图参考ID下面)该陈述应该给出底行的Aura计数1和顶行的Aura计数2。怎么了?
添加回答
举报
0/150
提交
取消