sql Query Design中的语法错误

时间:2014-09-24 20:46:51

标签: sql

我设计了一个查询,例如

Select Temp3.*

From (
              (Select temp1.alletec_ce1name,temp1.employeeid, count (temp1.alletec_mifid) AS MifAssign,alletec_mifid
     from (select  MIF.alletec_ce1name,User1.employeeid,MIF.alletec_mifid from Filteredalletec_mif as MIF FULL OUTER JOIN FilteredSystemUser As User1 on MIF.alletec_ce1=User1.systemuserid 
              FULL OUTER JOIN FilteredBusinessUnit as BU ON User1.businessunitid=BU.businessunitid 
              where MIF.alletec_organisationname='Konica Minolta India' AND MIF.alletec_cityname ='Delhi' AND
                     MIF.alletec_regionname ='North' ) as temp1
Group by temp1.alletec_mifid,temp1.alletec_ce1name,temp1.employeeid ) as Temp2 Inner Join FilteredIncident As Incident On Incident.alletec_serialnomif=Temp2.alletec_mifid ) as temp3

现在问题是它在第一个附近显示语法错误。可能的原因是什么?提前谢谢。

我还有一个查询,例如

with temp2 (
alletec_ce1name,
employeeid,
alletec_mifid,
alletec_cityname,
alletec_regionname

)
as(
Select temp1.alletec_ce1name,temp1.employeeid, temp1.alletec_mifid, temp1.alletec_cityname,temp1.alletec_regionname
from (select  MIF.alletec_ce1name,User1.employeeid,MIF.alletec_mifid,  MIF.alletec_regionname, MIF.alletec_cityname from Filteredalletec_mif as MIF FULL OUTER JOIN FilteredSystemUser As User1 on MIF.alletec_ce1=User1.systemuserid 
              FULL OUTER JOIN FilteredBusinessUnit as BU ON User1.businessunitid=BU.businessunitid 
             where MIF.alletec_organisationname='Konica Minolta India' AND (MIF.alletec_cityname ='Delhi') AND
                     (MIF.alletec_regionname ='North') ) as temp1
                     )


select temp2.alletec_ce1name,temp2.employeeid, temp2.alletec_regionname,temp2.alletec_cityname, count(alletec_mifid) as MIFASSIGN,
   Incident.alletec_casecalltypename
from temp2  Left Outer join FilteredIncident As Incident On Incident.alletec_serialnomif=temp2.alletec_mifid 
group by  temp2.alletec_ce1name,temp2.employeeid,temp2.alletec_mifid,temp2.alletec_regionname,temp2.alletec_cityname,
   Incident.alletec_casecalltypename 

现在,因为我有一个临时表。我希望有一个临时表,以便可以合并我temp2的最后一个可执行表值。看看你是否可以帮忙。感谢

2 个答案:

答案 0 :(得分:0)

您的查询相当于

select
    *
from
    (table) as temp3

这是无效的,你不能把括号放在那里。额外的嵌套水平被打破了。您需要执行以下操作:

select
    *
from
    table

或类似

select
    *
from (
    select
        *
    from
        table
    ) as temp3

您的第一个查询可能会简化为:

Select 
    *
From (
    select  
        MIF.alletec_ce1name,
        User1.employeeid,
        MIF.alletec_mifid,
        count (MIF.alltec_mifid) as MifAssign
    from 
        Filteredalletec_mif as MIF 
            full outer join
        FilteredSystemUser As User1 
            on MIF.alletec_ce1 = User1.systemuserid 
            full outer join 
        FilteredBusinessUnit as BU 
            on User1.businessunitid=BU.businessunitid 
    where 
        MIF.alletec_organisationname = 'Konica Minolta India' AND 
        MIF.alletec_cityname ='Delhi' AND
        MIF.alletec_regionname ='North' 
    group by
        MIF.alletec_mifid,
        MIF.alletec_ce1name,
        User1.employeeid
    ) as temp1
        Inner Join 
    FilteredIncident As Incident 
        On Incident.alletec_serialnomif = Temp1.alletec_mifid;

答案 1 :(得分:0)

算上你的括号,我认为它们不匹配。