如何将文件中的最后一行作为行计数但其他所有列都为NULL? [英] how to get the last row in file as row count but all other columns to be NULL?
问题描述
嗨朋友们,
我使用行计数转换将行计数作为最后一列,但行数填充在所有列中。
例如我的文件应该是这样的
ABC RowCnt
xyz NULL
ghi NULL
klm 3
RowCnt栏中的3表示记录总数。
我实现了这个目标:(
ABC RowCnt
xyz 3
ghi 3
klm 3
我坚持这个。请帮助我实现第一个结果。
提前致谢。
Hi Friends,
I have used row count transformation to get the row count as final column but the row count populates in all the columns.
e.g. My file should look like this
A B C RowCnt
x y z NULL
g h i NULL
k l m 3
The "3" in the "RowCnt" column says the total number of records.
I achieved this :(
A B C RowCnt
x y z 3
g h i 3
k l m 3
I am stuck with this. Please help me in achieving the first result.
Thanks in advance.
推荐答案
你可以做类似的事情 -
You can do something like -
SELECT A,B,C
,CASE WHEN ROW_NUMBER() OVER(ORDER BY A,B,C)=(SELECT COUNT(*) FROM dbo.YourTable)
THEN (SELECT COUNT(*) FROM dbo.YourTable)
ELSE NULL END AS RowCnt
FROM dbo.YourTable
如果这没有帮助,请分享你到目前为止尝试的sql以获得问题所示的o / p。
希望,它有助于:)
If this doesn't help, please share the sql you have tried so far to get the o/p as shown in the question.
Hope, it helps :)
这篇关于如何将文件中的最后一行作为行计数但其他所有列都为NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!