部门有限而且知道: sql server:select 产品名称, sum(数量) as 合计, sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1, sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2, ... sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N group by 产品名称 union all select '合计' as 产品名称, sum(数量) as 合计, sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1, sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2, ... sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N如果是其他数据库或者部门不知道请说明。
我用的是access数据库,应该差不错一样吧。
在VFP中用交叉表查询做:语句为: SELECT A.产品名, A.部门名, SUM(A.数量); FROM '原始表.DBF' A; GROUP BY A.产品名, A.部门名; ORDER BY A.产品名, A.部门名; INTO CURSOR SYS(2015) DO (_GENXTAB) WITH 'Query',.t.,.t.,.t.,,,,.t.,0,.f. BROWSE NOMODIFY
Sum(Case When 部门名称='部门1' then 数量 end)'部门1' 含这个语句执行的时候出现错误信息:‘不支持此接口’。 我用的是access数据库,该怎样解决?
只不过排列方式而已。
若非要如此只能用临时表解决了。过程并不不简单哪。
sql server:select 产品名称,
sum(数量) as 合计,
sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1,
sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2,
...
sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N
group by 产品名称
union all
select '合计' as 产品名称,
sum(数量) as 合计,
sum(case when 部门名称='部门1' then 数量 else 0 end) as 部门1,
sum(case when 部门名称='部门2' then 数量 else 0 end) as 部门2,
...
sum(case when 部门名称='部门N' then 数量 else 0 end) as 部门N如果是其他数据库或者部门不知道请说明。
SELECT A.产品名, A.部门名, SUM(A.数量);
FROM '原始表.DBF' A;
GROUP BY A.产品名, A.部门名;
ORDER BY A.产品名, A.部门名;
INTO CURSOR SYS(2015)
DO (_GENXTAB) WITH 'Query',.t.,.t.,.t.,,,,.t.,0,.f.
BROWSE NOMODIFY
含这个语句执行的时候出现错误信息:‘不支持此接口’。
我用的是access数据库,该怎样解决?