我正在使用以下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
答案 0 :(得分:2)
为什么每个连接之间都有','?不需要逗号!
就像:
SELECT <COLUMNS>
FROM <TABLE1>
INNER JOIN <TABLE2> ON <JOIN FIELDS>
INNER JOIN <TABLE3> ON <JOIN FIELDS>
WHERE <FILTER CONDITIONS>
答案 1 :(得分:0)
您需要一个基表来加入!
Select
CompanyStatus,
Companyname,
INNER JOIN Compan...
需要第一张桌子
Select
CompanyStatus,
Companyname
FROM some_table
INNER JOIN Compan...
还要摆脱那些逗号!
答案 2 :(得分:0)
您在公司名称
之后的查询中缺少From子句Select CompanyStatus, Companyname .
^ from clause
join的一般语法是,
select column_name
from Table_name 1
Inner/Left/Right/cross Join Table_name 2
ON condition