1

这是查询,我有 3 个内部连接的表,现在我希望通过在我的管理员的 php 上执行查询来计算结果中的所有行,即 78,我不想要表的结果,我只想要 wchich 中的 1 行写的东西是 78,和我们在

SELECT count (*) FROM test_table

下面是3个内联表的查询

        SELECT 
mybb_users.uid,
mybb_users.username,
mybb_users.avatar,
mybb_posts.fid,
mybb_posts.uid,
mybb_posts.dateline,
mybb_posts.tid,
mybb_posts.subject,
mybb_forums.parentlist,
mybb_forums.fid
FROM mybb_forums
    INNER JOIN mybb_posts ON mybb_forums.fid = mybb_posts.fid
    INNER JOIN mybb_users ON mybb_posts.uid = mybb_users.uid
    WHERE mybb_forums.parentlist LIKE '%58%'
    GROUP BY mybb_posts.tid
    ORDER BY mybb_posts.dateline DESC

现在如何计算其中的总行数?

已编辑

 SELECT count( mybb_users.uid ) AS totalOfRows
FROM (

SELECT mybb_users.uid, mybb_users.username, mybb_users.avatar, mybb_posts.fid, mybb_posts.uid AS uidPost, mybb_posts.dateline, mybb_posts.tid, mybb_posts.subject, mybb_forums.parentlist, mybb_forums.fid AS fidForum
FROM mybb_forums
INNER JOIN mybb_posts ON mybb_forums.fid = mybb_posts.fid
INNER JOIN mybb_users ON mybb_posts.uid = mybb_users.uid
WHERE mybb_forums.parentlist LIKE '%58%'
GROUP BY mybb_posts.tid
)T

错误 ::#1054 -“字段列表”中的未知列“mybb_users.uid”

4

1 回答 1

2

好吧,如果您不想要结果,为什么要显示这些字段?选择返回一个表,因此对其应用计数:

SELECT 
count(*)
FROM mybb_forums
    INNER JOIN mybb_posts ON mybb_forums.fid = mybb_posts.fid
    INNER JOIN mybb_users ON mybb_posts.uid = mybb_users.uid
    WHERE mybb_forums.parentlist LIKE '%58%'
    GROUP BY mybb_posts.tid

另外,你是按帖子分组的,所以,不需要订购

编辑:我认为我发布的查询应该有效,无论如何,如果不是,这绝对应该有效:

SELECT sum(Total) AS totalOfRows 
FROM ( 

SELECT 1 as Total 
FROM mybb_forums 
INNER JOIN mybb_posts ON mybb_forums.fid = mybb_posts.fid 
INNER JOIN mybb_users ON mybb_posts.uid = mybb_users.uid 
WHERE mybb_forums.parentlist LIKE '%58%' 
GROUP BY mybb_posts.tid 
)T
于 2012-08-25T15:10:06.800 回答