(使用MYSQL) 我需要找出特定月份每天有多少人订阅。 到目前为止,这是我的查询:
function populateData(data) {
$(".studentPanel").show();
for (var i = 0; i < data.length; i++) {
$(".totalFee" + i).val(data[i].total.amount);
for (var j = 0; j < data[i].submissions.length; j++) {
var ts = new Date(data[i].submissions[j].created_at);
var dateString = ts.getDate() + "-" + ts.getMonth() + "-" + ts.getYear();
console.log(data[i].submissions[j].amount);
var
tr = $("<tr>"),
td1 = $("<td>"),
td2 = $("<td>"),
td3 = $("<td>"),
td4 = $("<td>"),
btnUpdate = $("<button class='btn btn-primary Update'>"),
btnDelete = $("<button class='btn btn-danger Delete'>");
$(".feeTable" + i).append(tr);
tr.append(td1).append(td2).append(td3).append(td4);
td1.append(data[i].submissions[j].amount);
td2.append(dateString);
td3.append(btnUpdate);
td4.append(btnDelete);
btnUpdate.append("Update");
btnDelete.append("Delete");
btnUpdate.click((event) => {
//put whatever your updateFees function does in here
console.log(event);
console.log(data[i].submissions[j].id); //your data is acessible
});
btnDelete.click((event) => {
//put whatever your deleteFees function does in here
console.log(event);
console.log(data[i].submissions[j].id); //your data is acessible
});
}
}
}
我希望输出给我:
SELECT COUNT(user_ID) AS Subs, DATE(subscription_date) AS Day_Joined FROM Users GROUP BY DAY(Day_Joined), user_ID HAVING MONTH(Day_Joined) = 03 ORDER BY Day_Joined
到目前为止,它给了我
subs Day_Joined
- 10 2018-03-04
- 20 2018-03-05
- 30 2018-03-06
答案 0 :(得分:0)
您应仅按Day_Joined分组
SELECT COUNT(user_ID) AS Subs
, DATE(subscription_date) AS Day_Joined
FROM Users
GROUP BY DATE(subscription_date)
HAVING MONTH(DATE(subscription_date)) = 03
ORDER BY
如果您也按user_id分组,则您不存在与众不同的user_id的计数。