【问题标题】:How to find user information using mysql query如何使用mysql查询查找用户信息
【发布时间】:2016-03-22 05:50:00
【问题描述】:

我想从mysql查询中找到用户idEmail

我在mysql数据库中有三个表

  1. 用户 2.photographer_timetables 3.jobs

1.用户

2.photographer_timetables

3 个职位

这是我的查询

   SELECT Users.id AS `Users__id`
      , Users.email AS `Users__email` 
   FROM users          Users 
   LEFT 
   JOIN photographer_timetables pt    
     ON (pt.user_id = users.id AND role =3) 
  RIGHT JOIN jobs jb 
     ON (jb.photographer_id = pt.user_id 
     AND HOUR(jb.job_time) !='12:00:00'  
     AND jb.job_date !='2016-03-21')    
 WHERE (HOUR(start_time) <= '08:00:00'  
    AND weekday = 1)

我要查找job_datejob_time中没有的用户信息

我的 sql 查询返回空白,但 o/p 应该至少在行上

提前致谢

【问题讨论】:

  • 考虑提供正确的 CREATE 和 INSERT 语句,以及所需的结果。

标签: php mysql json database


【解决方案1】:

您可以使用NOT EXISTS

查询

select * from users
where not exists (
  select 1 from jobs
  where jobs.user_id = users.id
);

希望一旦工作结束,您将从jobs 表中删除该行。

如果您想检查在特定日期谁都有空。那么

查询

select * from users
where not exists (
  select 1 from jobs
  where jobs.user_id = users.id
  and jobs.job_date = '2016-03-23' -- change the date accordingly
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 2015-01-17
    相关资源
    最近更新 更多