English 中文(简体)
需要核实我是否理解SQL逻辑
原标题:Need to verify I am understanding SQL Logic

我想知道这个SQL逻辑的解码是否正确。这是SQL:

,[hrs].[Hours] - SUM(CASE WHEN [UnitState].[UnitStateType] <>  ACTIVE  THEN [Allocation].[AllocatedEnergyMwh] ELSE 0 END / CAST([Unit].[NetDependableCapacity] AS FLOAT)) AS SH

我的解释是:

if [UnitState].[UnitStateType] does not equal active then SH equals the sum of [Allocation].[AllocatedEnergyMwh] / 
    (float)[Unit].[NetDependableCapacity].  

else SH = [hrs].[Hours] 
最佳回答

不尽然

SH没有else 。 其它的只影响总和。 更准确地说, 它说:

SH = hours -
 (the sum of AllocatedEnergyMwh where StateType != ACTIVE) / NetDependableCapacity

其它的仅用于忽略活动分配的能源Mwh的总和。 在这些情况中, 设置分配的能源Mwh = 0 来做到这一点 。

问题回答

它关闭了,但你错过了[时 。 [小时] - 案件的一部分,第一个。

if [UnitState].[UnitStateType] does not equal active
    then SH equals [hrs].[Hours] minus the sum of [Allocation].[AllocatedEnergyMwh] / (float)[Unit].[NetDependableCapacity].  

else SH = [hrs].[Hours] minus (0)/[Unit].[NetDependableCapacity]

如果[联合国]。 [联合国类型]并不等于当时的活跃状态。

[hrs].[时 减去([分配]. [分配的能源Mwh]/[单位].[净可依赖的能力])

以其他方式

[hrs].[小时]减去总和(0/[单位].[Netdefaitable Captacity]) -- -- & gt; 意指[hrs].[小时] - 0





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签