以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  公式转换为SQL语句  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=130808)

--  作者:lihe60
--  发布时间:2019/2/2 8:35:00
--  公式转换为SQL语句
(1001.qm+1002.qm)/(1001.qm-1009.qm)
转换为
(sum(case when code=\'1001\' then qm end)+sum(case when code=\'1002\' then qm end))/(sum(case when code=\'1001\' then qm end)-sum(case when code=\'1009\' then qm end))
[此贴子已经被作者于2019/2/2 8:35:29编辑过]

--  作者:有点蓝
--  发布时间:2019/2/2 9:12:00
--  
没看明白。表结构是怎么样的?
--  作者:lihe60
--  发布时间:2019/2/2 9:28:00
--  
表结构是这样的

           code      qm
1         1001       2
2         1002       3
3         1009       4


结果=-5/2,code远不止这几个数据。

[此贴子已经被作者于2019/2/2 9:29:42编辑过]

--  作者:有点蓝
--  发布时间:2019/2/2 9:46:00
--  
如果code只有这3种情况,参考:http://www.foxtable.com/webhelp/scr/2965.htm

如果code不是固定的,没有办法使用一条sql处理,只能是分组统计后,使用代码计算