由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to find intersection of two tables
相关主题
请教比较两个table,找出相同和不同的records合并table的问题大家帮帮忙
求求!waiting onlinesmall problem about DAO
INTERSECTAccess database 求助
how to particially delete record in sql serverMS ACCESS 里面怎么把两个Table combine 到一个table, 而且primary key不重复呢?
Asking help for Access!:(SQL Server 问题 -- 怎样 UPDADATE 才快
How to find a duplicate record in Access?清理table的常识建议
请问一个SQL语句的优化问题SQL fast search in a 10 million records table (转载)
mysql maximum columns <=1000?两个Excel上的问题
相关话题的讨论汇总
话题: date话题: state话题: records话题: tables
进入Database版参与讨论
1 (共1页)
l******n
发帖数: 9344
1
Two tables A and B. A has Date and State. B also has Date and State.
A has 20 records and B has 50.
For all records, how can we find out the number of records in A that has
Date and State intersection with B.
for example, if A has
2/1/2008-3/1/2008, CA
B has
2/12-2/14/2008, TX,CA, OR
Then this record is what we want. I want to count these records.
Any way?
thanks in advance
c*****d
发帖数: 6045
2
呵呵,欢迎longtian版主光临数据库版
先介绍几个deal给我们吧 ;-)
估计这个就是个人使用
所以规范化,效率也就不用太严格了
tab_A (start_date, end_date, state)
tab_B (start_date, end_date, state1, state2, state3)
select * from tab_A a, tab_B b
where a.start_date < b.start_date
and a.end_date > b.end_date
and a.state in (b.state1, b.state2, b.state3)

【在 l******n 的大作中提到】
: Two tables A and B. A has Date and State. B also has Date and State.
: A has 20 records and B has 50.
: For all records, how can we find out the number of records in A that has
: Date and State intersection with B.
: for example, if A has
: 2/1/2008-3/1/2008, CA
: B has
: 2/12-2/14/2008, TX,CA, OR
: Then this record is what we want. I want to count these records.
: Any way?

B*****g
发帖数: 34098
3
你也搞deal?
我觉得sql应该是
select * from tab_A a, tab_B b
where a.start_date > b.end_date
and a.end_date > b.start_date
and a.state in (b.state1, b.state2, b.state3)

【在 c*****d 的大作中提到】
: 呵呵,欢迎longtian版主光临数据库版
: 先介绍几个deal给我们吧 ;-)
: 估计这个就是个人使用
: 所以规范化,效率也就不用太严格了
: tab_A (start_date, end_date, state)
: tab_B (start_date, end_date, state1, state2, state3)
: select * from tab_A a, tab_B b
: where a.start_date < b.start_date
: and a.end_date > b.end_date
: and a.state in (b.state1, b.state2, b.state3)

b*****e
发帖数: 364
4
Yes. Intersection.

【在 B*****g 的大作中提到】
: 你也搞deal?
: 我觉得sql应该是
: select * from tab_A a, tab_B b
: where a.start_date > b.end_date
: and a.end_date > b.start_date
: and a.state in (b.state1, b.state2, b.state3)

1 (共1页)
进入Database版参与讨论
相关主题
两个Excel上的问题Asking help for Access!:(
请问如何算出这个天数来How to find a duplicate record in Access?
sql question请问一个SQL语句的优化问题
sql query questionmysql maximum columns <=1000?
请教比较两个table,找出相同和不同的records合并table的问题大家帮帮忙
求求!waiting onlinesmall problem about DAO
INTERSECTAccess database 求助
how to particially delete record in sql serverMS ACCESS 里面怎么把两个Table combine 到一个table, 而且primary key不重复呢?
相关话题的讨论汇总
话题: date话题: state话题: records话题: tables