对你来说简单,对我来说太难了. [英] Simple for you, too hard for me.
问题描述
我该如何将库存更改为:
1H011,TY06S-6000-NA,2
1H013,TB07H-6400-NA,4
1H013,TS95V-9400-NB,2
1H013,TY05H-6400-NA,5
1H021,TY06S-6000-NA,10
1H023,TY05H-6400-NA,1
从这里开始:
1H013,TS95V-9400-NB,1
1H013,TY05H-6400-NA,3
1H013,TY05H-6400-NA,1
1H013,TB07H-6400-NA,2
1H021,TY06S-6000-NA,10
1H013,TS95V-9400-NB,S
1H013,TY05H-6400-NA,S
1H023,TY05H-6400-NA,S
1H013,TB07H-6400-NA,S
1H011,TY06S-6000-NA,S
1H013,TB07H-6400-NA,M
1H011,TY06S-6000-NA,M
如您所见,已对它们进行排序,对相同的文件求和,并且S和M = 1.
需要使用脚本吗?并且没有字典或主文件?
how would i change my stocktake to this:
1H011,TY06S-6000-NA,2
1H013,TB07H-6400-NA,4
1H013,TS95V-9400-NB,2
1H013,TY05H-6400-NA,5
1H021,TY06S-6000-NA,10
1H023,TY05H-6400-NA,1
from this:
1H013,TS95V-9400-NB,1
1H013,TY05H-6400-NA,3
1H013,TY05H-6400-NA,1
1H013,TB07H-6400-NA,2
1H021,TY06S-6000-NA,10
1H013,TS95V-9400-NB,S
1H013,TY05H-6400-NA,S
1H023,TY05H-6400-NA,S
1H013,TB07H-6400-NA,S
1H011,TY06S-6000-NA,S
1H013,TB07H-6400-NA,M
1H011,TY06S-6000-NA,M
as you can see it is sorted, same files are summed and the S''s and M''s =1.
need to do it with a script? and without a dictionary or master file?
推荐答案
您将需要在选择中执行SUM()
,利用GROUP BY
来确定总和的分解,一个CASE
语句检索值,然后使用ORDER BY
对其进行排序:
You will need to do aSUM()
in your selection, utilizing aGROUP BY
to identify the breakup of the sums, aCASE
statement to retrieve values, then useORDER BY
to sort them:
SELECT
Column1,
Column2,
SUM(
CASE
WHEN column3 IN ('S', 'M')
THEN 1
ELSE CAST(column3 AS int)
END
) AS SumOfColumn3
FROM
sourceTable
GROUP BY
Column1,
Column2
ORDER BY
Column1,
Column2
这篇关于对你来说简单,对我来说太难了.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!