我有以下查询来获取每月用户数量:
SELECT count(user_id) from subs
where (started_at between @start_date and @start_date + interval 1 month
or (expires_at>@start_date + interval 1 month and started_at<@start_date))
如果我们有以下数据库:
user_id started_at expires_at
=============================
1 2015-01-01 2015-12-31
2 2015-01-01 2015-01-03
3 2015-02-01 2015-02-28
4 2015-03-01 2015-03-31
5 2015-04-01 2015-04-31
6 2015-04-01 2016-04-01
7 2015-05-01 2015-05-09
我需要一个返回下表的查询:
2015-01 - 2
2015-02 - 2(因为Jan记录中的一个没有到期,直到12月)
2015-03 - 2
2015-04 - 3
2015-05 - 3
等
那么在一个查询中获得此结果的有效方法是什么?
答案 0 :(得分:0)
您想要// simple function that converts the data to the markers on screen
function renderData() {
// the geometry that will contain all the cubes
var geom = new THREE.Geometry();
// add non reflective material to cube
var cubeMat = new THREE.MeshLambertMaterial({color: 0xffffff,opacity:0.6, emissive:0xffffff});
for (var i = quakes.length - 1; i >= 0; i--) {
var objectCache = quakes[i]["geometry"]["coordinates"];
// calculate the position where we need to start the cube
var position = latLongToSphere(objectCache[0], objectCache[1], 600);
// create the cube
var cubeGeom = new THREE.BoxGeometry(2,2,2000,1,1,1),
cube = new THREE.Mesh(cubeGeom, cubeMat);
// position the cube correctly
cube.position.set(position.x, position.y, position.z);
cube.lookAt( new THREE.Vector3(0,0,0) );
// merge with main model
geom.merge(cube.geometry, cube.matrix);
}
// create a new mesh, containing all the other meshes.
var combined = new THREE.Mesh(geom, cubeMat);
// and add the total mesh to the scene
scene.add(combined);
}
年份和月份。
假设您的GROUP BY
列属于DATE类型,您可以f.e.使用started_at
,或使用GROUP_BY YEAR(started_at), MONTH(started_at)
将列值格式化为单个字符串值,格式为YYYY-MM和GROUP BY。选择与列相同的值,以获得所需的正确标识符。
答案 1 :(得分:0)
你可能想要这样的东西:
(' ', " <font color='green'> info:</font> One, two, three, four, five.")
请注意,如果一个月没有用户,则此查询不会返回该月的条目。如果您还希望包含0个用户的月份,则需要更复杂的查询;查看this了解详情。