TB-汇总(3行4列):
名称 标识 资产原值 资产净值
合计
管理类计 1
生产类计 2
TB-明细(5行4列):
名称 标识 资产原值 资产净值
管理1 1 200 150
管理2 1 850 600
管理3 1 450 250
生产1 2 150 80
生产2 2 350 120
现在想将 (TB-明细) 表的资产原值列分类求和,即将管理*的资产原值求和后,更新到 (TB-汇总) 表的“管理类计”行去,生产类同样处理,请问这样的 SQL 语句怎么写?我是个新手,能不能详细解释一下语句,帮我在 ACCESS2003 中测试一下,急用,谢谢啦
9 个解决方案
#1
顶一下,怎么没人帮忙啊
#2
oo
#3
oo
#4
??
#5
??
#6
用DSUM解决
#7
没人会写吗?
看来还得去 SQL 板块才行啊,哎
看来还得去 SQL 板块才行啊,哎
#8
下面语句假设标识类型文本类型的:
SELECT "合计" AS 名称, "" AS 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计
FROM TB_明细
UNION SELECT "管理类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='1' group by 标识
UNION SELECT "生产类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='2' group by 标识
ORDER BY 标识
SELECT "合计" AS 名称, "" AS 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计
FROM TB_明细
UNION SELECT "管理类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='1' group by 标识
UNION SELECT "生产类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='2' group by 标识
ORDER BY 标识
#9
把上面的查询追加到汇总表
INSERT INTO TB_汇总 ( 名称, 标识, 资产原值, 资产净值 )
SELECT 查询5.名称, 查询5.标识, 查询5.资产原值合计, 查询5.资次净值合计
FROM 查询5;
INSERT INTO TB_汇总 ( 名称, 标识, 资产原值, 资产净值 )
SELECT 查询5.名称, 查询5.标识, 查询5.资产原值合计, 查询5.资次净值合计
FROM 查询5;
#1
顶一下,怎么没人帮忙啊
#2
oo
#3
oo
#4
??
#5
??
#6
用DSUM解决
#7
没人会写吗?
看来还得去 SQL 板块才行啊,哎
看来还得去 SQL 板块才行啊,哎
#8
下面语句假设标识类型文本类型的:
SELECT "合计" AS 名称, "" AS 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计
FROM TB_明细
UNION SELECT "管理类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='1' group by 标识
UNION SELECT "生产类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='2' group by 标识
ORDER BY 标识
SELECT "合计" AS 名称, "" AS 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计
FROM TB_明细
UNION SELECT "管理类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='1' group by 标识
UNION SELECT "生产类计" AS 名称, 标识, Sum(资产原值) AS 资产原值合计, sum(资产净值) AS 资次净值合计 FROM TB_明细 where 标识='2' group by 标识
ORDER BY 标识
#9
把上面的查询追加到汇总表
INSERT INTO TB_汇总 ( 名称, 标识, 资产原值, 资产净值 )
SELECT 查询5.名称, 查询5.标识, 查询5.资产原值合计, 查询5.资次净值合计
FROM 查询5;
INSERT INTO TB_汇总 ( 名称, 标识, 资产原值, 资产净值 )
SELECT 查询5.名称, 查询5.标识, 查询5.资产原值合计, 查询5.资次净值合计
FROM 查询5;