问题描述
下面是我用来创建视图的 SQL 查询
Below is the SQL Query I used to create as view
使用批量插入dbo.IC_Raw_In
将数据导入该表,数据类型为Money,I_Date除外.
and the data is imported to this table by useing a bulk insert dbo.IC_Raw_In
and data type are Money except I_Date.
然后当我运行查询时,即.
Then when i ran the query i.e,.
select * from v_AMP_C i
得到以下作为输出
现在我想编写一个 SQL 查询,以在名为 C12WR 的新列中获取结果以解决以下问题.
Now I want write a SQL Query to get results in new Column called C12WR for the below question.
我想排除(使用 NULL)C12WR 列的前 11 行,并在 C12WR 列的第 12 行使用AMPS12_C"中的静态值(在上表结果中,值为510.3958"标记为粗体.每次我将数据导入我的表时,该值都会发生变化,因此每次都会动态变化.并且在 AMPS12_C 列中,它应该在第 13 行到表末尾之后计算以下公式.
I want to exclude(Use NULL) the first 11 rows in C12WR Column, and in 12th row of C12WR Column "use a static value which is in "AMPS12_C" (In the above shown table results the value is "510.3958" marked as bold). This value will change every time i import the data to my table so the will change dynamically every time. And in the AMPS12_C Column it should calculate the below formula after 13th row to end of the table.
所以如果我计算它应该代表上面的公式如下..(我不想使用任何静态值......对于这个公式的例子,我在这里采用静态值只是为了结果容易解释)
so if i calculate it should represent above formulas as below..(I don't want to use any static values...for the example of this formula I am taking a static values here just for the results to easy of explanation)
在运行所需的查询后,我应该得到类似于下面的输出
and after run the desired query i should get the output similar to below
寻求帮助写上面的SQL Query
looking for help to write above SQL Query
推荐答案
这个概念有一定的错误" - 主要是因为 X 行和 Y 行之间的任何此类行相互关系都依赖于按指定顺序排列的行- 我没有看到现在.IT 与 SQL 语言的基于集合的方面背道而驰.
There is a certain 'wrongness' with the concept - primarily because any such row inter-relation between row X and Y relies on the rows being in a specified order - which I do not see present. IT goes against the set-based aspects of the SQL language in effect.
就 SQL 而言 - 缓慢/昂贵的方法是将表连接到自身,但您必须能够使用排名函数创建行号确定性才能使其工作.
In terms of SQL - the slow / expensive way to do it is to join the table to itself, but you have to be able to create row numbers deterministicallt using a ranking function for this to work.
标准 T-SQL 没有 Lag/Lead 能力(引用上一行/下一行的能力.) - 它确实存在于 MDX 语言中,但这使这进一步复杂化.
Standard T-SQL does not have a Lag / Lead ability (the abilty to reference the previous / nextrow.) - It does exist in the MDX langauge but that complicates this further.
这篇关于在第 13 行动态和第 12 行静态值之后使用公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!