计算同一会员表中 2 个日期之间的推荐人新会员
我现在正在进行的项目需要一个参考系统(目前他们有 50K 成员)。我决定在成员表中添加 ref 和 ref_id 字段。
members表的结构;
id (int auto),
admin (enum (1,0)),
ref (enum (1,0)),
ref_id (int),
country_id (int),
city_id(int),
town_id(int),
totalRef (int),
fullName (varchar),
registrationDate (datetime)
我想列出两个日期之间有新成员的推荐人数据。我想提供更多详细信息,因此我还尝试在查询中添加国家/地区、城市和城镇。我尝试了以下查询,但考虑到加载需要很长时间,我认为这不是一个好方法;
SELECT m.id, m.fullName, m.country_id, m.city_id, m.town_id, m.totalRef,
(select name from country where country.id = m.country_id) as countryName,
(select name from city where city.id = m.city_id) as cityName,
(select name from town where town.id = m.town_id) as townName,
(select count(id) from members where members.ref_id = m.id AND ref_id > 0 AND registrationDate BETWEEN '2011.11.04 00:00:00' AND '2011.11.04 23:59:59') as newRef
FROM members as m
WHERE
m.country_id = '224' AND
m.city_id = '4567' AND
m.town_id = '78964' AND
m.admin = '0' AND
m.ref = '1'
ORDER BY newRef DESC
LIMIT 0, 25
如果您能帮助我解决这个问题,我将很高兴。先感谢您。
The project I'm working on right now needs a reference system (currently they have 50K members). I decided to add ref and ref_id field in members table.
Structure of members table;
id (int auto),
admin (enum (1,0)),
ref (enum (1,0)),
ref_id (int),
country_id (int),
city_id(int),
town_id(int),
totalRef (int),
fullName (varchar),
registrationDate (datetime)
I would like to list referers data which has new members between 2 dates. I wanted to provide a bit more details so I also tried to add country, city, and town in the query. I tried following query but I don't think this is a good approach to go with considering it takes really long time to load ;
SELECT m.id, m.fullName, m.country_id, m.city_id, m.town_id, m.totalRef,
(select name from country where country.id = m.country_id) as countryName,
(select name from city where city.id = m.city_id) as cityName,
(select name from town where town.id = m.town_id) as townName,
(select count(id) from members where members.ref_id = m.id AND ref_id > 0 AND registrationDate BETWEEN '2011.11.04 00:00:00' AND '2011.11.04 23:59:59') as newRef
FROM members as m
WHERE
m.country_id = '224' AND
m.city_id = '4567' AND
m.town_id = '78964' AND
m.admin = '0' AND
m.ref = '1'
ORDER BY newRef DESC
LIMIT 0, 25
I will be glad if you could help me about this problem. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西 -
Something like this -