0

我正在使用以下 Select 语句来检索和计算多个表中每个字段的总数。但是,在执行语句时,我收到错误“在单词连接处或附近出现语法错误”

任何帮助将不胜感激

询问:

Select CompanyStatus,Companyname,
        INNER JOIN Company on usersincompany.companyID=company.companyID,
                INNER JOIN company on users.companyID=Company.companyID,
                 INNER JOIN usersincompany on users.userid=usersincompany.userid,
                INNER JOIN users on userstatus.userstatudid=users.userstatusid,
                INNER JOIN users on project.companyid=users.companyid,
                INNER JOIN users on usersession.userid=users.userid,
                INNER JOIN project on template.projectid=project.projectid,
                INNER JOIN project on merchendisingarea.projectid=project.projectid,
                 INNER JOIN merchendisingarea on publishstatus.publishstatusid=merchendisingarea.publishstatusid,
             INNER JOIN template on merchendisingmodule.templateid=template.templateid,
        INNER JOIN company on companyaccountclassification.classificationtypeid=company.classificationtypeid,
sum(distinct users.userid) as TotalUsers,
sum(case when users.userstatusid =2 then 1 else 0 end) as Activeusers,
sum(case when users.userstatusid =3 then 1 else 0 end) as SuspendedUsers,
sum(distinct usersessionid) as TotalLogin,
sum(distinct merchendisingmoduleid) as CurrentModules,
count( merchendisingmodule.createddate) as Modulescreated,
count( merchendisingmodule.updateddate) as Modulesupdated,
sum(distinct merchendisingareaid) as Currentareas,
count( merchendisingarea.createddate) as AreasCreated,
count( merchendisingarea.updateddate) as Areasupdated,
sum(case when publishingstatus.publishstatusid =1 then 1 else 0 end) as SuccessPublished,
sum(case when publishingstatus.publishstatusid =3 then 1 else 0 end) as FailedPublished  

 from users,company,merchendisingmodule,merchendisingarea,publishingstatus, usersession       group by companystatus, companyname
4

3 回答 3

2

为什么每个连接之间都有“,”?不需要逗号!

把它像:

    SELECT <COLUMNS> 
    FROM <TABLE1> 
    INNER JOIN <TABLE2> ON <JOIN FIELDS>
    INNER JOIN <TABLE3> ON <JOIN FIELDS>
    WHERE <FILTER CONDITIONS>
于 2013-06-17T13:58:58.810 回答
0

您需要一个基表才能加入!

Select
    CompanyStatus,
        Companyname,
    INNER JOIN Compan...

需要第一张桌子

Select
    CompanyStatus,
        Companyname
    FROM some_table
    INNER JOIN Compan...

并摆脱那些逗号!

于 2013-06-17T13:59:02.403 回答
0

您在 Companyname 之后的查询中缺少 From 子句

Select  CompanyStatus, Companyname .
                                  ^ from clause 

连接的一般语法是 as ,

select column_name 
from Table_name 1
Inner/Left/Right/cross Join Table_name 2
ON condition
于 2013-06-17T14:03:08.780 回答