gpt4 book ai didi

mysql - MyBatis 数据映射。收藏。关系表

转载 作者:行者123 更新时间:2023-11-29 23:41:59 24 4
gpt4 key购买 nike

基金分配模板

template_id | 模板名称 | 状态 |

1 大乐透 1

2 EZ-2 1

fund_allocation_item

|项目 ID |项目名称 |状态|

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;

表单或页面输出

|分配模板名称 |基金模板百分比|状态 |

| super 乐透 | 100% |活跃|

| EZ-2 | 86% |活跃 |

问题:如何才能显示具有给定域和表格设计的每个基金模板的总百分比?

最佳答案

使用以下查询:

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;

关于mysql - MyBatis 数据映射。收藏。关系表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26119432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com