Select a.name ,mamoubt=(Select sum(amount) From 表 where id<10 And name=a.name),
namoubt=(Select sum(amount) From 表 where id>=50 And name=a.name)
from 表 a Group By a.name
namoubt=(Select sum(amount) From 表 where id>=50 And name=a.name)
from 表 a Group By a.name
namoubt=(Select sum(amount) From 表 where id>=50 And name=a.name)
from 表 a Group By a.name
mamoubt=(select sum(convert(float,amount)) from test2 where convert(int,id)<10 and name=a.name ),
mamoubt=(select sum(convert(float,amount)) from test2 where convert(int,id)>=50 and name =a.name )
from test2 a
Group By name
mamoubt=(select sum(convert(float,amount)) from test2 where convert(int,id)<10 and name=a.name ),
mamoubt=(select sum(convert(float,amount)) from test2 where convert(int,id)>=50 and name =a.name )
from test2 a
Group By name
mamoubt=select sum(amount) from table) a where b.id>50 and name=b.name
from table
group name
sum(case when id<10 then amount else 0 end ) as mamoubt,
sum(case when id>50 then amount else 0 end ) as namoubt
from table
group by name
sum(case when id<10 then amount else 0 end ) as mamoubt,
sum(case when id>50 then amount else 0 end ) as namoubt
from table
group by name这个是最好的呀!