【发布时间】:2017-10-02 13:30:37
【问题描述】:
我正在使用 angularjs。我正在尝试使用连接查询来显示计数。我有三个表。它的结构如下所示
筹款活动
fundraiserId
1
筹款用户
fundraisinguserId userId fundraiserId
1 1 1
用户
userId //and other columns
1
现在我正在编写类似这样的查询
SELECT f.fundraiserId
, fu.userId
FROM fundraisers f
LEFT
JOIN fundraisingusers fu
ON f.fundraiserId = fu.fundraiserId
LEFT
JOIN users u
ON fu.userId = u.userId;
现在在前面的 html 中,我想显示用户数,即fundraisingusers 表中存在的用户数。在这种情况下 1。但现在我不知道如何在联接查询中获取计数。目前我正在获取 userId .我需要将其显示为计数而不是 ID。
这是我的html
<div class="col-xs-6 col-sm-4 col-md-4" data-ng-repeat="fundraise
in fundraises">
<span class="glyphicon glyphicon-thumbs-up"></span>Supporters
<h6>{{fundraise.userId}}</h6>//Here i need count of users from fundraisingusers table but i am getting userId
</div>
这是我用来显示数据的 POJO 类
public class Fundraisers implements Serializable{
private Integer fundraiserId;
private Integer userId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "fundraiserId")
public Integer getFundraiserId() {
return fundraiserId;
}
public void setFundraiserId(Integer fundraiserId) {
this.fundraiserId = fundraiserId;
}
@Transient
@JoinColumn(insertable=false,updatable=false)
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
这是我的数据库访问 dao 代码
@Override
public List<Fundraisers> getFundsByIndexWithStatusForFront()
{
List<Fundraisers> fundRaisers = new ArrayList<Fundraisers>();
Query query =
sessionFactory.getCurrentSession().createSQLQuery(FUNDRAISES);//Here i am using above query
query.setResultTransformer(Transformers.aliasToBean(Fundraisers.class));
fundRaisers = query.list();
return fundRaisers;
}
谁能告诉我如何获得 userId 而不是 userId 的计数?
【问题讨论】:
-
绝对没有点外部加入您从中选择任何列的表。
-
我还有其他专栏。但出于发布目的,我认为这些没有必要