我该如何评估此查询?

时间:2021-09-21 20:10:52

This query give me error:Msg 156, Level 15, State 1, Line 10 Incorrect syntax near the keyword 'where'.

此查询给出错误:消息156,级别15,状态1,行10关键字'where'附近的语法不正确。

declare @date1 datetime,@date2 datetime , @COUNT INT , @countgap int, @order int
seLECT @date1='2009-05-11' , @date2 = '2009-05-12'
seLECT @countgap = 30 , @COUNT = 0, @order=23 

select VisitingCount from (
select count(page) as VisitingCount,   
    (datepart(hour,Date)*60+datepart(minute,Date))/@countgap as OrderNumber 
    from scr_SecuristLog  
    where Date between @date1 and  @date2
    GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) where OrderNumber=@order

2 个解决方案

#1


3  

Pherhaps:

Pherhaps:

GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 
HAVING OrderNumber=@order

or:

要么:

where (Date between @date1 and  @date2) AND OrderNumber=@order
GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 

#2


2  

You need to give your derived table a name e.g. DT1. Here I've reformatted the SQL text to my personal liking :) to make it easier to read:

您需要为派生表提供一个名称,例如DT1。在这里,我已经将SQL文本重新格式化为我个人喜欢的:),以便于阅读:

select DT1.VisitingCount 
  from (
        select count(page) as VisitingCount,   
               (datepart(hour,Date)*60+datepart(minute,Date))/@countgap 
                  as OrderNumber 
          from scr_SecuristLog  
         where Date between @date1 and  @date2
         GROUP 
            BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap
       ) AS DT1 
 where DT1.OrderNumber=@order

#1


3  

Pherhaps:

Pherhaps:

GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 
HAVING OrderNumber=@order

or:

要么:

where (Date between @date1 and  @date2) AND OrderNumber=@order
GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) 

#2


2  

You need to give your derived table a name e.g. DT1. Here I've reformatted the SQL text to my personal liking :) to make it easier to read:

您需要为派生表提供一个名称,例如DT1。在这里,我已经将SQL文本重新格式化为我个人喜欢的:),以便于阅读:

select DT1.VisitingCount 
  from (
        select count(page) as VisitingCount,   
               (datepart(hour,Date)*60+datepart(minute,Date))/@countgap 
                  as OrderNumber 
          from scr_SecuristLog  
         where Date between @date1 and  @date2
         GROUP 
            BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap
       ) AS DT1 
 where DT1.OrderNumber=@order