gpt4 book ai didi

mysql - mysql select 语句中的 if isnull

转载 作者:行者123 更新时间:2023-11-29 09:08:17 25 4
gpt4 key购买 nike

我有以下sql。如果子查询返回任何内容,我希望能够输入是/否(真/假)。

SELECT
post.topic_id,
topic.topic_posts,
topic.topic_title,
topic.topic_poster_name,
topic.topic_last_post_id,
topic.topic_start_time,
(SELECT post_time FROM bb_posts WHERE post_id = topic.topic_last_post_id) as last_post_time,
topic.topic_slug,
topic.topic_posts,
`group`.name AS group_name,
`group`.slug AS child_slug,
`parent`.slug AS parent_slug,
(SELECT id FROM table WHERE condition = 1) as isTrue << subquery
FROM bb_posts post
LEFT JOIN bb_topics topic
ON topic.topic_id = post.topic_id
LEFT JOIN bb_forums forum
ON topic.forum_id = forum.forum_id
LEFT JOIN wp_bp_groups_groupmeta groupmeta
ON forum.forum_id = groupmeta.meta_value
LEFT JOIN wp_bp_groups `group`
ON groupmeta.group_id = `group`.id
LEFT JOIN wp_bp_groups `parent`
ON `group`.parent_id = `parent`.id
$conditions
GROUP BY topic_id
ORDER BY $sort_col $dir
LIMIT $offset,$num

如果返回结果,我希望子查询返回"is"。

最佳答案

您可以使用计数(*):

SELECT 0 != (SELECT COUNT(*) FROM(子查询))

如果子查询返回任何内容,则返回 1。

关于mysql - mysql select 语句中的 if isnull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430528/

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