fund_allocation_template
template_id | template_name | 状态 |
1 Mega Lotto 1
2 EZ-2 1
fund_allocation_item
| item_id | item_name |状态|
1慈善1
2操作费用1
3食物津贴1
4交通津贴1
| 5 |灾难受害者| 1 |
r_template_item
| template_id | item_id | item_percentage |
1 1 45.00
1 2 55.00
2 1 40.00
2 2 46.00
//FundAllocationTemplate.java(domain)
private Integer templateID;
private String templateName;
private Integer templateStatus
//FundAllocationItem.java(domain)
private Integer itemID;
private String itemName;
private Integer itemStatus
<resultMap id="fundTemplate" type="FundAllocationTemplate">
<id property="fundTemplateID" column="template_id" />
<result property="fundTemplateName" column="template_name" />
<result property="fundTemplateStatus" column="status" />
//Association for Status
</resultMap>
<resultMap id="fundItem" type="FundAllocationItem">
<id property="fundItemID" column="item_id" />
<result property="fundItemName" column="item_name" />
<result property="fundItemStatus" column="status" />
//Association for Status
</resultMap>
FORM
private Integer templateID;
private String templateName;
private BigDecimal totalPercentage;
private Integer status;
| Mega Lotto | 100%|有效|
问题:如何在给定的域名和表格设计中显示每个基金模板的总百分比?
答案 0 :(得分:0)
使用以下查询:
select T.template_name,SUM(R.item_percentage) as Fund_Template_Percentage,
(CASE T.status WHEN 1 THEN "Active" ELSE "NOT Active" END) STATUS
from fund_allocation_template T, r_template_item R
where T.template_id=R.template_id
GROUP BY R.template_id;