[英]Using Join and Between to Link Tables and Find Values
我正在嘗試加入這兩個表並獲得結果,保留表 1 中的所有結果並從表 2 中找到值(如果在表 2 匹配條件中找不到任何內容,則返回 NULL)
表格1
|ROUTE|MEASURE|
|:---:|:-----:|
|1|6|
|1|12|
|2|1|
|3|2|
|3|5|
表2
|ROUTE|BEGINMEASURE|ENDMEASURE|VALUE|
|:---:|:-----:|:--:|:--:|
|1|0|5|A|
|1|5|10|B|
|2|0|5|C|
|3|0|3|D|
|3|3|10|E|
|3|10|12|F|
我的代碼是:
select t1.route, t1.measure, t2.value
from table1 t
left join table2 t2 on t1.route=t2.route
where t1.route=t2.route and t1.measure between t2.beginmeasure and t2.endmeasure;
將條件添加到聯接:
select t1.route, t1.measure, t2.value
from table1 t
left join table2 t2 on t1.route=t2.route and t1.measure between t2.beginmeasure and t2.endmeasure;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.