SELECT
[GName],
case when charindex('abc',GName)>0 then 150 else 30 end as key1,
case when charindex('bu',GName)>0 then 100 else 50 end as key2
(key1 + key2) as abc
FROM mytable 想把key1 + key2 起来到abc,看提示出错。怎么才可以加起来呢
[GName],
case when charindex('abc',GName)>0 then 150 else 30 end as key1,
case when charindex('bu',GName)>0 then 100 else 50 end as key2
(key1 + key2) as abc
FROM mytable 想把key1 + key2 起来到abc,看提示出错。怎么才可以加起来呢
from
(
SELECT
[GName],
case when charindex('abc',GName)>0 then 150 else 30 end as key1,
case when charindex('bu',GName)>0 then 100 else 50 end as key2
(key1 + key2) as abc
FROM mytable
)aa
(
SELECT
[GName],
case when charindex('abc',GName)>0 then 150 else 30 end as key1,
case when charindex('bu',GName)>0 then 100 else 50 end as key2
FROM mytable
group by [GName]
)
tt
group by [GName]
from
(SELECT
[GName],
case when charindex('abc',GName)>0 then 150 else 30 end as key1,
case when charindex('bu',GName)>0 then 100 else 50 end as key2
FROM mytable
)aa
(
SELECT
[GName],
max(case when charindex('abc',GName)>0 then 150 else 30 end) as key1,
max(case when charindex('bu',GName)>0 then 100 else 50 end) as key2
FROM mytable
group by [GName]
)
tt
group by [GName]
[GName],
sum(case when charindex('abc',GName)>0 then 150 else 30 end) as key1,
sum(case when charindex('bu',GName)>0 then 100 else 50 end) as key2 ,
sum(case when charindex('bu',GName)>0 then 100 else 50 end)+sum(case when charindex('bu',GName)>0 then 100 else 50 end)
FROM mytable
group by [GName]?