将 SELECT 查询的结果添加到另一个 SELECT 查询中

Add the result of SELECT query in another SELECT query

这是两个 SELECT

的 UNION 的结果
SELECT count(*) FROM
((SELECT session_id_current_user from test.tws_analytics 
        WHERE (add_date BETWEEN '2022-05-15' AND '2022-05-15') AND ((pathURL='vues/login.php' AND name_current_user='') OR (pathURL='' AND searchURL='?job=forgotten' AND name_current_user=''))
        AND session_id_current_user NOT IN 
        (SELECT session_id_current_user from test.tws_analytics 
        WHERE (pathURL <> 'vues/login.php' AND searchURL <> '?job=forgotten') AND add_date BETWEEN '2022-05-15' AND '2022-05-15' order by session_id_current_user)
        order by session_id_current_user)
    UNION 
(SELECT name_current_user from test.tws_analytics where add_date BETWEEN '2022-05-15' AND '2022-05-15' AND name_current_user IS NOT NULL AND name_current_user <> ''))
AS tem

结果是 11。

我想做的是 select 这个结果与其他列类似:

SELECT count(session),count(name), [AND tem.count(*)] FROM ....

这是总体思路,虽然我不知道如何实现它。

简化的一般答案是

select * from (select count(*) numsessions from sessions), (select count(*) numusers from users)

这将给出 2 个不同的计数,我没有包括您提供的逻辑,但这需要在 2 个子查询中完成。