这是我用于拆分克隆的 sql 表:
#1) Table name: sp_user
|user_id |username
+--------------------
|1 |user1
|2 |user2
|3 |user3
|4 |user4
#2) Table name: sp_group
|group_id |groupname |bill
+--------------------------------
|1 |shopping |2000
|2 |lunch |1000
'movie' 组的费用由用户 - user1、user2 共享,'lunch' 组的费用由用户 - user1、user2、user3、user4 共享。
#3)Table name: sp_usergroup
|group_id |user_id
+---------------------
|1 |1
|1 |2
|2 |1
|2 |2
|2 |3
|2 |4
我正在使用 request promise 对端点 /user_expense?uname=user1 进行编码,如下所示:
router.route("/user_expense").get(function (req, res) {
var uname = req.param('name');
// select query to get the user_id for 'user1' and store it as uid
.......
// select query to get the list of group_id for uid
// set user_exp = 0
for (i= each of the group_id) {
// select count(*) for group_id[i] to get the number of users in this group and store it as ct
// select the bill for group_id[i] and store it as b
// user_exp += ct / b
}
res.send(user_exp);
}
对于 user1,费用金额应为 1250/- (1000 + 250) 为这个单个请求设置批量查询是否有效,如何做?