使用sqlite命令连接2个表

使用sqlite命令连接2个表,sqlite,join,Sqlite,Join,我已经创建了一个名为sample.db的数据库 我已经导入了2个csv文件-test和test1(数据库中的表) 我想根据3列(时间戳、经度和纬度)连接这两个表 试验 测试1 预期产量 ozone,particullate_matter,carbon_monoxide,sulfure_dioxide,nitrogen_dioxide,longitude,latitude,timestamp,avgMeasuredTime,avgSpeed,medianMeasuredTime,Distance

我已经创建了一个名为sample.db的数据库

我已经导入了2个csv文件-test和test1(数据库中的表)

我想根据3列(时间戳、经度和纬度)连接这两个表

试验

测试1

预期产量

ozone,particullate_matter,carbon_monoxide,sulfure_dioxide,nitrogen_dioxide,longitude,latitude,timestamp,avgMeasuredTime,avgSpeed,medianMeasuredTime,Distance between 2 points,duration of measurements,ndt in kmh
61,82,52,49,54,10.2466,56.2091,1410693900,61,60,61,1030,52,71
66,83,51,44,51,10.2466,56.2091,1410694200,61,60,61,1030,52,71
68,80,54,41,56,10.2466,56.2091,1410694500,63,58,63,1030,52,71
66,79,53,42,59,10.2466,56.2091,1410694800,71,52,71,1030,52,71
71,75,57,45,61,10.2466,56.2091,1410695100,67,55,67,1030,52,71
75,75,60,50,61,10.2466,56.2091,1410695400,62,59,62,1030,52,71
122,97,172,40,53,10.2507,56.2026,1412101200,67,55,67,1030,52,71
如您所见,我想根据时间戳、经度和纬度加入。表2中有两个经度值(test1)。所以我想比较表1中的经度与表2中的经度值。同样的纬度

我试过的

select * 
from test 
join test1 
    on test.timestamp=test1.TIMESTAMP and
    test.longitude=test1.Long1 or 
    test.longitude=test1.Long2 and 
    test.latitude=test1.Lat1 or 
    test.latitude=test1.Lat2;
我还想将结果存储在一个新表中


我是sqlite的新手。所以请帮助:)

用于
内部连接的SQL命令

SELECT latitude
FROM test
INNER JOIN test1 ON test.latitude = test1.latitude;

对其他列重复此操作。

使用括号对条件进行分组。您需要时间戳匹配和的行(lat/long pair 1匹配或lat/long pair2匹配)


请正确标记。你试过什么?我没有看到SQL语句显示您尝试的内容不起作用。请从测试中选择*加入测试1(test.latitude=test1.latitude和test.longitude=test1.longitude和test.timestamp=test1.timestamp)请不要将答案放在注释中。特别是当他们不正确的时候。@Sloacher先生,我已经提到了我的尝试。这非常有效,先生!您能告诉我如何将结果存储在新表中吗?从SELECT语法查找INSERT。基本上,创建一个SELECT语句来返回目标表中的列,并将其用作INSERT语句的数据源。非常感谢,先生:)
select * 
from test 
join test1 
    on test.timestamp=test1.TIMESTAMP and
    test.longitude=test1.Long1 or 
    test.longitude=test1.Long2 and 
    test.latitude=test1.Lat1 or 
    test.latitude=test1.Lat2;
SELECT latitude
FROM test
INNER JOIN test1 ON test.latitude = test1.latitude;
select * 
from test 
join test1 
    on test.timestamp = test1.TIMESTAMP and
    ((test.longitude = test1.Long1 and test.latitude = test1.Lat1) or
     (test.longitude = test1.Long2 and test.latitude = test1.Lat2));