dongxibeng5324 2015-06-25 21:36
浏览 45

子查询的每一行的sql where子句

I have 2 tables in MSSql

table_a:

data|id_1|timeInIntForm
------------------------------
data1 | 1/22323/3 | 1433721600
data2 | 1/22323/3 | 1433721660

and I have another table

table_b

data|(string list of ids)|startTimeinIntform|EndTimeInIntForm
--------------------------------------------------------------
dataA| (a_1223233_z a_1223233_x) | 1433721601 | 1433721659
datab| (a_1223233_z a_1223233_x) | 1433721602 | 1433721645

I want to do a

select * from table_a where id_1 = 'someId' 
and timeInIntForm between 'time1' and 'time2' 
and not between TableB_row1[startTimeinIntform] and TableB_row1[EndTimeInIntForm]'
.
.
.
and not between TableB_rowN[startTimeinIntform] and TableB_rowN[EndTimeInIntForm]'

The ids do not match but can be correlated on a different table that has

table_c:

data|id_1|id_2
-----------------------------
data| 1/22323/3 | a_1223233_z
data| 1/22323/4 | a_1223233_x

my initial thought is in PHP to get the rows from table_b and then as I select from table_a build the not between clause from each row in table_b. But I would LOVE to do this in one select statement if possible. Any ideas?

I edited it to have some "sample" data I was asked for. I am stumped on how to join these .. I admit freely I am not a pro or even poor at joins but I am really stumped on how to join table b to a and c

  • 写回答

1条回答 默认 最新

  • dongzhukuai8177 2015-06-25 21:55
    关注

    Well I am not sure exactly without the tables but I think this would do it.

    Select a.*
    From table_a a
    join table_c c
    on a.ID_1 = c.ID_1
    join table_b b
    on c.ID_2 = b.ID_2
    Where a.ID_1 = 'someid'
    and a.timeinintform not between 'time1' and 'time2'
    and a.timeinintform not between b.starttimeininform and b.endtimeinintform
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度