[英]mysql group_concat showing all dates
我有2张桌子:
配置文件userid, fname,lname
时间表: userid, date, start_time, end_time
这是我的查询。
从配置文件中选择*,group_CONCAT(distinct(date),'_',start_time,'_',end_time)作为dateformat,计划WHERE profile.userid = schedule.pid
这将返回表中的所有日期。 但是我想做的是只返回某些天,例如:
date >= DATE(NOW()) and date <= date(now() + 2 day)
所以今天明天和后天。
无论我尝试什么,它都只返回日程表数据库中的所有日期。 我需要返回2行userid 5在配置文件中有1行,但在计划中有5行,而userid 6在配置文件中有1行,在计划中有2行,查询工作正常,它只返回所有日期,而不返回
"date >= DATE(NOW()) and date <= date(now() + 2 day)"
您尝试过GROUP BY吗?
如WHERE profile.userid = schedule.pid GROUP BY date
选择profile.userid,schedule.userid,group_CONCAT(distinct(date),'_',start_time,'_',end_time)作为dateformat from profile,schedule WHERE profile.userid = schedule.userid and date> = DATE(NOW( ))和日期<= date(now()+间隔2天);
现在做到了! 现在,我可以在php中使用dateformat变量来解析我的结果。
kanishka panamaldeniya-感谢您的建议!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.