我使用基于列表的报告。此列表包含三个元素:
副标题 记录 分类汇总 等等...
每行都有一个格式标记:
H Subtitle
R Record
S Subtotal
首先,我根据记录创建一个唯一代码列表
SELECT DISTINCT ON (rec_code) rec_code FROM records
然后我循环这个"列表"在我的前端工具中并获取每个代码的记录
SELECT * FROM records where rec_code=list.rec_code
这是完成工作的一种相当简单的方法,但速度很慢。
我最接近的是模仿小计。但仍缺少字幕和标签
select rec_code, rec_sum
from (
select rec_code, 'name' as name, rec_sum, rec_code as o
from rec as a
union all
select 'Subtotal', 'name' as name, sum(rec_sum), rec_code as o
from rec as a
group by rec_code
) as a
order by o, rec_sum
http://sqlfiddle.com/#!3/270d6/10
这是此sqlfiddle
的所需输出H code a
R A 1
R A 2
S Subtotal 3
H code b
R B 3
R B 3
S Subtotal 6
这可能吗?怎么样?
提前感谢您的任何线索!
答案 0 :(得分:1)
您应该在应用程序层执行此格式化。但是,您可以将更接近的SQL查询放在一起。 For instance:
select rec_code, rec_sum
from (
select rec_code, 'name' as name, rec_sum, rec_code as o, 2 as o2
from rec as a
union all
select 'Subtotal', 'name' as name, sum(rec_sum), rec_code as o, 2 as o2
from rec as a
group by rec_code
union all
select code_name, 'header' as name, NULL, code_id as o, 1 as o2
from code
) a
order by o, o2, rec_sum;
答案 1 :(得分:1)
class App(npyscreen.NPSAppManaged):
def onStart(self):
self.registerForm("MAIN", MainForm())
class MainForm(npyscreen.Form):
def create(self):
self.add(npyscreen.TitleText, name = "Text:", value= "Hello" )
def afterEditing(self):
self.parentApp.setNextForm(None)