gpt4 book ai didi

sql - 从联合 mysql 查询中获取帖子数?

转载 作者:行者123 更新时间:2023-11-29 01:00:02 24 4
gpt4 key购买 nike

SELECT u.id       AS pid    ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE
FROM (
(SELECT b.id AS id ,
b.pid AS pid ,
b.message AS MESSAGE,
b.uid AS uid,
b.date AS DATE
FROM wall_posts AS b
JOIN Friends AS f
ON f.id = b.pid
WHERE f.buddy_id = '1'
AND f.status = 'b'
ORDER BY DATE DESC
LIMIT 0, 10
)

UNION
(SELECT id ,
pid ,
MESSAGE,
uid,
DATE
FROM wall_posts
WHERE pid = '1'
ORDER BY DATE DESC
LIMIT 0, 10
)
) AS b2
JOIN Users AS u
ON b2.pid = u.id
WHERE u.banned ='0'
AND u.email_activated='1'
ORDER BY DATE DESC
LIMIT 0, 10

是代码。不确定我将如何获得帖子数。我知道通常我会做 select count(*) as num 我试过了

所以我做了什么

SELECT u.id       AS pid    ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE
FROM

并将其更改为

SELECT COUNT(u.id       AS pid    ,
b2.id AS id ,
b2.message AS MESSAGE,
b2.uid AS uid,
b2.date AS DATE) as num
FROM

并对所有选择语句做了类似的事情,但是没有用,不断收到类似 #1064 的错误 - 你的 SQL 语法有错误;查看与您的 MySQL 服务器版本对应的手册,了解在第 1 行的“AS pid、b2.id AS id、b2.message AS MESSAGE、b”附近使用的正确语法。那么我将如何去计数呢?我需要我的分页 php 类的计数。

最佳答案

COUNT 函数不允许您拥有多个列。它可以是 COUNT(*) 或 COUNT(column_name),其中只有一个列名。 COUNT(*) 格式计算总行数,其中 COUNT(column_name) 返回指定列的非空值的计数。

因此,下一步是在 SELECT 中更改您的 COUNT。然后,如果存在其他问题,您可以从那里开始。

关于sql - 从联合 mysql 查询中获取帖子数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3947049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com