0

我有一张包含Manager以下字段详细信息的表格,

 Name,   ID 

和一个子表Appoinments,它将包含以下字段,

Manager ID , Date, Appoinment Details.

现在我需要从 Maneger 表中获取 maneger 的详细信息,那些今天没有预约的人。

我是 SQL 新手。请帮我写查询

4

3 回答 3

3

注意我假设您使用的是 SQL Server。

select m.*
  from manager m
 where not exists (select *
                     from appointments a
                    where m.id = a.manager_id
                      and a.date >= datediff(d,0,getdate())
                      and a.date <  datediff(d,-1,getdate()));

注意:
datediff(d,0,getdate()) = 今天
datediff(d,-1,getdate()) = 明天

于 2013-05-08T06:40:24.163 回答
1
select * from manager m
where not exists
(
    select 1
    from appointments a
    where a.manager = m.manager
    and a.date = today (whatever today in your SQL is)
)
于 2013-05-08T06:41:23.023 回答
0

其他答案是正确的,这是一个加入版本:

SELECT M.Name, M.ID
FROM manager M LEFT JOIN appointments A ON M.id = A.manager_id
WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, A.date)) != DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
GROUP BY M.Name, M.ID;
于 2013-05-08T07:08:20.587 回答