SELECT
(SELECT COUNT(*) FROM table1) AS count1 WHERE date='2019-06-12',
(SELECT COUNT(*) FROM table2) AS count2 WHERE date='2019-06-12'
为什么该语句在“,”或附近引起语法错误?
答案 0 :(得分:3)
需要在子查询中添加where clause
SELECT
(SELECT COUNT(*) FROM table1 WHERE date='2019-06-12') AS count1 ,
(SELECT COUNT(*) FROM table2 WHERE date='2019-06-12') AS count2
答案 1 :(得分:1)
尝试一下-
SELECT
(SELECT COUNT(*) FROM table1 WHERE date='2019-06-12') AS count1 ,
(SELECT COUNT(*) FROM table2 WHERE date='2019-06-12') AS count2
答案 2 :(得分:0)
让我们重写该语句,用简单的值替换括号中的SELECT
:
SELECT
1 AS count1 WHERE date='2019-06-12',
2 AS count2 WHERE date='2019-06-12'
现在很容易看到,直到逗号为止,您都有一个有效的SQL查询,但是您要追加要选择的其他值,这是无效的。
我假设您要在子查询中包含WHERE
:
SELECT
(SELECT COUNT(*) FROM table1 WHERE date='2019-06-12') AS count1,
(SELECT COUNT(*) FROM table2 WHERE date='2019-06-12') AS count2