不同

时间:2016-09-26 10:26:12

标签: sql sql-server

我尝试从3张表中获取特定时间内特定公交车号码的数据,但结果没有任何意义......

我的脚本是:

SELECT 
    distinct b.OraReg as date_and_time,
    b.IdMezzo as bus_number, b.StatoPorte as open_doors,
    b.speed as speed, lc.codazultimafermata as platform_number,
    n.descrnodo as platform_name
FROM 
    table 1 as b
INNER JOIN
    table 2 lc ON lc.id = b.IdMezzo
INNER JOIN
    table 3 n ON n.codaznodo = lc.codazultimafermata
WHERE
    b.OraReg BETWEEN '2016-08-21 14:24:00' AND '2016-08-21 14:29:30' 
    AND b.IdMezzo = 17  
    AND lc.codazultimafermata IN ('47487', '47537') 
    AND lc.orainvio BETWEEN '2016-08-21 14:24:00' AND '2016-08-21 14:29:30'
ORDER BY
    b.OraReg 

我的结果每行都有重复的值,虽然我做的很明显......我做错了什么?

date_and_time   bus_number  open_doors  speed   platform_number
---------------------------------------------------------------
24:01.1         17          0           0       47487
24:01.1         17          0           0       47537
24:16.8         17          0           32      47487
24:16.8         17          0           32      47537
24:21.3         17          0           41      47487
24:21.3         17          0           41      47537
24:47.8         17          0           54      47487
24:47.8         17          0           54      47537
25:10.9         17          0           9       47487
25:10.9         17          0           9       47537
25:26.6         17          0           41      47487
25:26.6         17          0           41      47537
25:42.1         17          0           5       47487
25:42.1         17          0           5       47537
25:44.9         17          1           0       47487


tables structure - 
 table 1 - 
 OraReg datetime    Checked
 IdMezzo    int Unchecked
 StatoPorte tinyint Checked
 speed  tinyint Checked

 table 2 - 

 dataora    datetime    Unchecked
 codazultimafermata int Checked


 table 3 - 
 cinnodo    int Unchecked
 codaznodo  int Checked
 descrnodo  varchar(50) Checked

0 个答案:

没有答案