请问下我这条sql那里有问题

tt个23 2014-11-15 05:26:37
select user_name ,regist_Time,contact_name,company_phone,company_name from front_user where exists(select user_id,DAYOFMONTH(apply_time)as day from user_log where 1=1
#if($start_time &&!$start_time.equals(""))
and apply_time > '$start_time'
#end
#if($end_time &&!$end_time.equals(""))
and apply_time < '$end_time'
#end
group by user_id,DAYOFMONTH(apply_time)) ss group by day


我是想把user_log表中的userid 全取出来,跟frontuser表中的userid进行对比 ,讲相同userid的用户信息输出来,但是执行后并没有执行子查询中的,请问是为什么
...全文
215 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pony520 2014-11-17
  • 打赏
  • 举报
回复
select user_id from user_log where 1=1 and apply_time > '$start_time' and apply_time < '$end_time' group by user_id 这个加上时间,可能没有数据的,两表关联可能没有结果。单独执行一次,有没有数据在看一下
ayzen1988 2014-11-17
  • 打赏
  • 举报
回复


//你要把user_log表中user_id全部取出来,直接group by user_id就行了,为什么还要加上时间
//或者distinct(user_id)
//然后关联表查询,不知道是不是你想要的
select a.user_name,a.regist_Time,a.contact_name,a.company_phone,a.company_name from front_user a,
(select user_id from user_log where 1=1 and apply_time > '$start_time' and apply_time < '$end_time' group by user_id) ss
where a.user_id = ss.user_id

ACMAIN_CHM 2014-11-15
  • 打赏
  • 举报
回复
建议在PHP中加入调试代码以确定实际的SQL语句是什么。

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧