关键字On附近的语法不正确

时间:2021-09-19 22:55:51

I'm trying to make a query at work in which I count all occurrences of an id in one table and then I link the description and the colors associated with those ids from another.

我正在尝试在工作中进行查询,我在其中计算一个表中所有出现的id,然后将描述和与这些ID相关联的颜色从另一个表中链接。

But I seem to have botched up my SQL Syntax (it's been a while, sorry!). It's probably just a silly mistake and I'd be so greatful to whoever could help me out!

但我似乎搞砸了我的SQL语法(已经有一段时间了,抱歉!)。这可能只是一个愚蠢的错误,无论谁能帮助我,我都会非常感激!

SELECT 
    t1.activity_status_id,
    count(*),
    t2.description,
    t2.color
FROM
    dbo.Activity t1
INNER JOIN (
    dbo.Activity_Status t2 ON t1.activity_status_id = t2.id)
GROUP BY
    activity_status_id

2 个解决方案

#1


2  

 SELECT t1.activity_status_id,
       Count(*),
       t2.description,
       t2.color
FROM   dbo.Activity t1
       INNER JOIN dbo.Activity_Status t2
               ON t1.activity_status_id = t2.id
GROUP  BY t1.activity_status_id ,t2.description,t2.color 

#2


2  

Just remove unnecessary brackets ( and ) around inner join:

只需删除内连接周围不必要的括号(和):

SELECT ....
FROM
    dbo.Activity t1
    INNER JOIN dbo.Activity_Status t2 ON t1.activity_status_id = t2.id
GROUP BY ....

#1


2  

 SELECT t1.activity_status_id,
       Count(*),
       t2.description,
       t2.color
FROM   dbo.Activity t1
       INNER JOIN dbo.Activity_Status t2
               ON t1.activity_status_id = t2.id
GROUP  BY t1.activity_status_id ,t2.description,t2.color 

#2


2  

Just remove unnecessary brackets ( and ) around inner join:

只需删除内连接周围不必要的括号(和):

SELECT ....
FROM
    dbo.Activity t1
    INNER JOIN dbo.Activity_Status t2 ON t1.activity_status_id = t2.id
GROUP BY ....