查询以从表中获取丢失的日期 [英] query to get missing date from tables
本文介绍了查询以从表中获取丢失的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好..
我有两张桌子,就像一张是:
hi all..
i have two tables like one is:
s.no name
1 sam
2 jhon
3 sonu
4 rams
另一个表,例如
another table like
name date
sam 1/12/2011
jhon 1/13/2011
rams 1/13/2012
sonu 1/14/2012
rams 1/15/2012
当我从2012年1月11日提供日期,到2012年1月15日提供给我的名称为`rams`
在这里,我需要获取结果(第二张表中没有名称,日期女巫)
when i giving from date as 1/11/2012 and to date as 1/15/2012 and name as `rams`
Here i need to get result as (the name,date witch is not there in second table)
rams 1/11/2012
rams 1/12/2012
rams 1/14/2012
我曾尝试过
i was tried like
SELECT name FROM tbl1 WHERE (name NOT IN (select name from tbl2 where (` date` between '" + d1 + "' AND '"+ d2 +"'))) order by name;
这将返回名称,但不显示第二个表中缺少的日期
有人可以帮我解决这个非常复杂的查询吗..
在此先感谢..
this returns names but not display date missing in second table
can any one please help me for this much complex query..
thanks in advance..
推荐答案
尝试一下,仅使用伪SQL:
Try this, pseudo SQL only:
SELECT
tbl1.name,
tbl2.date
FROM tbl1
LEFT JOIN tbl2 ON tbl1.name = tbl2.name
WHERE tbl2.date NOT between d1 AND d2 order by tbl1.name;
我想你想在第一个表中显示名称,如果这样的话,该表在table2中没有指定日期. ..
试试这个..
I think u want to display the name in first table which does not have specified date in table2 if so...
try this..
select name from First where Name not in (
select name from Second where date between '2012-01-10' and '2012-01-14') ;
这篇关于查询以从表中获取丢失的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文