我正在尝试通过加入 join_id 列来从表 tb2 中获取键的数量。
这是我正在尝试的查询:
SELECT b.key, COUNT(*)
FROM tb1 AS a
INNER JOIN tb2 AS b
WHERE(a.DATE BETWEEN '2017-05-01' and '2017-05-30') AND a.DESC1 = 'payment
method' AND a.DESC IN ('automobiles')
AND a.join_id = b.join_id
GROUP BY b.key;
我得到SQL状态:42601和错误代码:-104错误。任何建议都会很棒。
提前致谢!!
答案 0 :(得分:1)
你有一个" 1"而不是" a"作为表a的别名
如果你使用这种语法,你还需要在连接后使用ON子句(你可以在where中加入,但是你需要一个逗号而不是INNER JOIN语句。
SELECT b.key, COUNT(*)
FROM tb1 AS a
INNER JOIN tb2 AS b ON a.join_id = b.join_id
WHERE(a.DATE BETWEEN '2017-05-01' and '2017-05-30') AND a.DESC1 = 'payment
method' AND a.DESC IN ('automobiles')
GROUP BY b.key;
答案 1 :(得分:0)
试试这个:
SELECT b.key, COUNT(*)
FROM tb1 a INNER JOIN tb2 b ON a.join_id = b.join_id
WHERE Date(a.DATE) BETWEEN '2017-05-01' and '2017-05-30'
AND a.DESC1 = 'payment method'
AND a.DESC = 'automobiles'
GROUP BY b.key