select t.pk_group as pk_group,
t.pk_org as pk_org,
t.pk_currtype as corigcurrencyid,
t.pk_order as pk_order,
SUM(case
WHEN orderstate=3 and ordertype!=4 THEN money
WHEN ordertype!=4 THEN money END) AS A
from table t
group by t.pk_order,
t.pk_group,
t.pk_org
t.pk_org as pk_org,
t.pk_currtype as corigcurrencyid,
t.pk_order as pk_order,
SUM(case
WHEN orderstate=3 and ordertype!=4 THEN money
WHEN ordertype!=4 THEN money END) AS A
from table t
group by t.pk_order,
t.pk_group,
t.pk_org
select t.pk_group as pk_group,
t.pk_org as pk_org,
max(t.pk_currtype) as corigcurrencyid,
t.pk_order as pk_order,
SUM(case
WHEN orderstate=3 and ordertype!=4 THEN money
WHEN ordertype!=4 THEN money END) AS A
from table t
group by t.pk_order,
t.pk_group,
t.pk_org
t.pk_org as pk_org,
t.pk_order as pk_order,
SUM(case
WHEN ORDERSTATUS=3 and T.ordertype!=4 THEN money END)AS AA,
SUM( case WHEN ORDERTYPE=4 THEN money END)AS BB
from table1 t
group by t.pk_order,
t.pk_group,
t.pk_org
第二个应该是ORDERTYPE=4
t.pk_org as pk_org,
t.pk_order as pk_order,
SUM(case
WHEN orderstate=3 and ordertype!=4 THEN money
WHEN ordertype=4 THEN money END) AS CNT
from table t
group by t.pk_order,
t.pk_group,
t.pk_org