一个复杂的数据汇总(SELECT-SQL):(20分)

  • 主题发起人 主题发起人 子龙
  • 开始时间 开始时间

子龙

Unregistered / Unconfirmed
GUEST, unregistred user!
一WJPZ.DBF数据库有四个字段:kmdm (C),kmmc (C),jfje (N),dfje (N)。
现要求按KMDM的前三位字符相同的记录汇总起来,用SELECT怎么写?我用
SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,KMMC,SUM(JFJE) AS JFJE,
SUM(DFJE) AS DFJE FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)通不过。
 
>>SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,KMMC,SUM(JFJE) AS JFJE,
>>SUM(DFJE) AS DFJE FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)通不过。

SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,SUM(JFJE) AS JFJE,
SUM(DFJE) AS DFJE FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)

即去掉KMMC
 
SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,KMMC,SUM(JFJE) AS JFJE,
union
SUM(DFJE) AS DFJE FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)
 
根本行不通
 
好像DELPHI中的SELECT限制多多啊!:(
 
我告诉你,INTERBASE数据库对扩展SQL支持远远不如现在很成熟的SQL SERVER和ORACLE
举个简单的例子:就是它居然连按计算列排序都不支持
select my_sum=sum(num),name
from table
group by id
order by my_sum
至于你说的更加复杂的自然更不支持了。
不过你可以自己写函数然后添加到INTERBASE数据库中
 
SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,SUM(JFJE) AS JFJE,
SUM(DFJE) AS DFJE,max(kmmc)
FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)

这样就行了!
 
SELECT SUBSTRING(KMDM FROM 1 FOR 3) AS KMDM,SUM(JFJE) AS JFJE,
SUM(DFJE) AS DFJE,max(kmmc)
FROM WJPZ GROUP BY SUBSTRING(KMDM FROM 1 FOR 3)

这样就行了!
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
832
import
I
后退
顶部