多个子查询结构中缺少某些内容

时间:2019-06-06 03:17:51

标签: mysql subquery

我正在尝试对2个表中的记录进行简单计数。我之前已经做过几次,但是目前无法访问常规系统。我确定我错过了最简单的事情,但是我感到压力很大,无法在任何地方找到答案。

我知道当我从一张桌子上拿出来时,它工作得很好。我想我只是想念一个愚蠢的逗号。

我的查询显示不正确。这是照片。

选择     COUNT() 从     T1 AS ct_hipotdb,     COUNT() 从     T2 AS task_resultdb

(SELECT 
    *
FROM
    ct_hipot
WHERE
    ACTOR_NAME LIKE ('MFG%')
        AND CONVERT_TZ(TIME_STAMP, 'UTC', 'US/Pacific') BETWEEN '2019/6/3 06:00:00' AND '2019/6/4 06:00:00') T1
(SELECT 
    *
FROM
    task_result
WHERE
    ACTOR_NAME LIKE ('MFG%')
        AND CONVERT_TZ(task_TIMESTAMP, 'UTC', 'US/Pacific') BETWEEN '2019/6/3 06:00:00' AND '2019/6/4 06:00:00') T2

QueryPhoto

1 个答案:

答案 0 :(得分:0)

缺少您的未显示为代码的第一部分。 像这样:

SELECT
      (
        SELECT
            COUNT(*)
        FROM
            ct_hipot
        WHERE
                ACTOR_NAME LIKE ('MFG%')
            AND CONVERT_TZ(TIME_STAMP, 'UTC', 'US/Pacific') BETWEEN '2019/6/3 06:00:00' AND '2019/6/4 06:00:00'
    ) AS ct_hipotdb
    , (
        SELECT
            COUNT(*)
        FROM
            task_result
        WHERE
                ACTOR_NAME LIKE ('MFG%')
            AND CONVERT_TZ(task_TIMESTAMP, 'UTC', 'US/Pacific') BETWEEN '2019/6/3 06:00:00' AND '2019/6/4 06:00:00'
    ) AS task_resultdb
;

P.S。我不会像您那样使用CONVERT_TZ函数,因为这将阻止查询使用索引。您应该将常量从TZ转换为UTZ。