求助求助!!!如何将查询出来的多条记录按照指定的两个字段汇总成一行记录
这是我现有语句
select FYear ,FAccountID,'B','' ,'111','111',
case when FPeriod='1' and FBeginBalance>0 then ABS(convert(money,FBeginBalance)) ELSE 0 end ,
case when FPeriod='1' and FBeginBalance<0 then ABS(convert(money,FBeginBalance)) ELSE 0 end ,
case when FPeriod='1' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='1' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='2' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='2' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='3' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='3' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='4' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='4' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='5' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='5' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='6' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='6' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='7' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='7' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='8' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='8' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='9' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='9' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='10' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='10' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='11' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='11' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='12' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='12' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='13' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='13' then convert(money,FDebit) ELSE 0 end,'0'
from t_Balance where FCurrencyID=1 and FYear='2008'and faccountid='1003'
查询出来结果为图片1

需要将查询出来的表按照前两个字段相同的话就汇总成一条记录,后面为金额字段则汇总求和
相关推荐
oracle某个字段多行记录转化为一行
oracle某个字段多行记录转化为一行,oracle某个字段多行记录转化为一行。
C# DataTable中查询指定字段名称的数据
主要介绍了C# DataTable中查询指定字段名称的数据,本文直接给出实例代码,简单易懂,需要的朋友可以参考下
mysql如何实现多行查询结果合并成一行
利用函数:group_concat(),实现一个ID对应多个名称时,原本为多行数据,把名称合并成一行
MySQL 查询某个字段不重复的所有记录
假设现在有如下N条记录 表明叫book id author title 1 aaa AAA 2 bbb BBB 3 ccc CCC 4 ddd DDD 5 eee AAA 现在想从这5条记录中查询所有title不重复的记录 select distinct title,author from book这样是不可以的 因为distinct只能作用于一个字段 想请教应该怎么写 答案: 代码如下:select a.* from book a right join ( select max(id) id from book group by title) b on b.id = a.id where
mysql批量更新多条记录的同一个字段为不同值的方法
首先mysql更新数据的某个字段,一般这样写: UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value'; 也可以这样用in指定要更新的记录: UPDATE mytable SET myfield = 'value' WHERE other_field in ('other_values'); 这里注意 ‘other_values’ 是一个逗号(,)分隔的字符串,如:1,2,3 如果更新多条数据而且每条记录要更新的值不同,可能很多人会这样写: foreach ($values as $id => $myv


疑难问题
