Sql 在这个SELECT语句中,单词“from”附近的错误在哪里?

Sql 在这个SELECT语句中,单词“from”附近的错误在哪里?,sql,sql-server,Sql,Sql Server,您能看到此MS SQL Server SELECT语句中的错误吗 select clientname, our_date_finalized as our_dat, specific_category as specific_c, SUM(total_allowed) as total_allo, SUM(total_charges) as total_char, SUM(savings) as savings, SUM(1) as claims

您能看到此MS SQL Server SELECT语句中的错误吗

select clientname, our_date_finalized as our_dat, 
    specific_category as specific_c, 
    SUM(total_allowed) as total_allo, 
    SUM(total_charges) as total_char, 
    SUM(savings) as savings, 
    SUM(1) as claims 
Group By 1, 2, 3 
Order By 1, 2, 3 
from lob_activity.dbo.lob_activity where lob = 'Reprc'
解析器说它在关键字“from”附近返回了一个错误。

您的from位于错误的位置

select 
      clientname
    , our_date_finalized as our_dat
    , specific_category as specific_c
    , sum(total_allowed) as total_allo
    , sum(total_charges) as total_char
    , sum(savings) as savings
    , sum(1) as claims
  from lob_activity.dbo.lob_activity
  where lob = 'reprc'
  group by clientname, our_date_finalized, specific_category
  order by 1, 2, 3

因为From和where子句必须位于Group By或order By之前

select clientname, our_date_finalized as our_dat, 
    specific_category as specific_c, 
    SUM(total_allowed) as total_allo, 
    SUM(total_charges) as total_char, 
    SUM(savings) as savings, 
    SUM(1) as claims 
from lob_activity.dbo.lob_activity 
where lob = 'Reprc'
Group By 1, 2, 3 
Order By 1, 2, 3 
是的,这是有效的:

select clientname, our_date_finalized as our_dat, specific_category as specific_c, SUM(total_allowed) as total_allo, SUM(total_charges) as total_char, SUM(savings) as savings, SUM(1) as claims from lob_activity.dbo.lob_activity where lob = 'Reprc' Group By clientname, equian_date_finalized, specific_category Order By 1, 2, 3

SELECT/FROM/WHERE/GROUP BY/HAVING/ORDER BY接近投票人请解释此问题如何不包含特定的问题代码或问题的解释?ORDER BY必须位于语句的末尾。您可以使用MS SQL Server按列数分组吗?似乎只有在使用专栏时才对我有效names@sgmoore我只是使用问题中的查询,但我继续使用列名更新了答案。