Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 是CTE';sybase中使用了什么?_Sql_Sybase_Common Table Expression - Fatal编程技术网

Sql 是CTE';sybase中使用了什么?

Sql 是CTE';sybase中使用了什么?,sql,sybase,common-table-expression,Sql,Sybase,Common Table Expression,我只是想知道cte是否也用于sybase…我知道cte用于sql server…但不知道它们是否用于sybase 如果Cte不用于sybase,sybase中是否有其他方法可以作为sql server中的Cte执行 我有这样一个问题:: select CONVERT(VARCHAR(7) , [startdatetime],111) AS [year-month] , nm.nameLine1 AS CompanyName , sum(datediff(hour, startdate

我只是想知道cte是否也用于sybase…我知道cte用于sql server…但不知道它们是否用于sybase

如果Cte不用于sybase,sybase中是否有其他方法可以作为sql server中的Cte执行

我有这样一个问题::

select CONVERT(VARCHAR(7)
  , [startdatetime],111) AS [year-month]
  , nm.nameLine1 AS CompanyName
  , sum(datediff(hour, startdatetime, enddatetime)) as total 
  from  srl 
  inner join  sr on srl.ServiceRequestId = sr.ServiceRequestId
  inner join Name nm
          on (sr.clientCustomerId = nm.customerId 
         and nm.nameTypeId = 'OFICE')
  where (startdatetime >= '08-01-2011 00:00:00.000'
    and enddatetime <= '10-31-2011 00:00:00.000')
  group by  CompanyName, [year-month]
  order by  CompanyName, [year-month]
我希望总数在输出中显示为: (我希望输出如下)

有什么方法可以做到这一点吗


提前感谢。

据我所知,从版本9开始的Sybase ASA确实支持CTE,但我不使用Sybase产品。对于您的查询,您不需要CTE,但我会使用普通

将以下内容添加到选择列表:

, SUM(totals) OVER (PARTITION BY [year-month], [CompanyName]) AS companytotals

以上查询是针对SYBASE的!!我知道;我只添加了一些空白以使其可读。我不认识Sybase,所以我不会对内容发表评论。请注意,如果你想得到准确的答案,你应该真正指定确切的产品名称和版本,Sybase是一家公司,而不是一种产品。它与:?@MichałPowaga::是的,你是对的..它与你回答的完全相同。试图得到一个答案的回应,所以我再次发布了这个..对不起,麻烦了。。!!再次感谢..!!::谢谢你的宝贵意见。。我尝试添加上面的查询以进行选择,但它不显示companytotal,而是显示与total相同的列。。
year-month CompanyName        total        companytotals   
---------- -----------     -----------    --------------- 
2011/08    B                    4 
2011/09    B                    7 
2011/10    B                    0            11
2011/08    E                   167 
2011/09    E                   212 
2011/10    E                   131           510
2011/08    L                    14 
2011/09    L                    23 
2011/10    L                     3          40
2011/08    O                    18 
2011/09    O                     8 
2011/10    O                     7           33
2011/08    S                    43 
2011/09    S                    60 
2011/10    S                    60          163
, SUM(totals) OVER (PARTITION BY [year-month], [CompanyName]) AS companytotals