我在下面有以下查询来从数据库中选择点。我需要稍微调整一下,我只想要'2013-09'的分数。我尝试通过简单地添加 AND "Time" LIKE '2013-09%' 来尝试,但这似乎不起作用,因为它会产生 0 条记录。我还知道数据库包含今年匹配的记录,因为我使用下面的查询(删除了时间选择部分)来选择所有记录。可能是什么问题?
; WITH positions AS (
SELECT MMSI
, Message_ID
, "Time"
, Latitude
, Longitude
FROM dbo.DecodedCSVMessages_Staging
WHERE Message_ID IN (1, 3)
AND Latitude > 45
AND Latitude < 85
AND Longitude < -50
AND Longitude > -141
AND "Time" LIKE '2013-09%' <- this is where I'd put it
)
, details AS (
SELECT MMSI
, Ship_Type
, Vessel_Name
, IMO
, Row_Number() OVER (PARTITION BY MMSI ORDER BY "Time" DESC) As row_num
FROM dbo.DecodedCSVMessages_Staging
WHERE Message_ID = 5
)
SELECT positions.MMSI
, positions.Message_ID
, positions."Time"
, details.Ship_Type
, details.Vessel_Name
, details.IMO
, positions.Latitude
, positions.Longitude
FROM positions
INNER
JOIN details
ON details.MMSI = positions.MMSI