1

我有一个无线电发射器检测列表,为了处理三角测量数据,我需要确保该站点有三个或更多接收器 ping 出来。

数据看起来像这样(除了在我的真实表中它是单个 DATETIME 字段):

Date    Time    Receiver    Location    Array   Transmitter
4/30/2013   6:14:34 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:17:11 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:19:21 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:20:37 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:22:05 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:23:55 AM  119736   D/s L side 1   A69-1303-48591
4/30/2013   6:23:57 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:26:35 AM  119736   D/s L side 1   A69-1303-48591
4/30/2013   6:26:37 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:28:52 AM  119736   D/s L side 1   A69-1303-48591
4/30/2013   6:28:53 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:30:20 AM  119736   D/s L side 1   A69-1303-48591
4/30/2013   6:30:22 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:32:13 AM  119736   D/s L side 1   A69-1303-48591
4/30/2013   6:32:15 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:32:16 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:34:57 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:34:58 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:37:18 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:37:19 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:38:55 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:38:56 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:41:07 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:42:25 AM  119732   D/s R side 1   A69-1303-48591
4/30/2013   6:42:26 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:43:59 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:46:00 AM  119740   U/s R side 1   A69-1303-48591
4/30/2013   6:57:12 AM  113177  U/s Site 1  1   A69-1303-48591

如您所见,这条鱼(A69-1303-48591)在一小时内至少击中了三个接收器(119732、119736、119740、113177),因此我可以对它的动作进行三角测量。这是我编写代码的新手尝试:

SELECT * FROM  detections WHERE 
((
recID_Detection = '113177' OR recID_Detection = '119732' OR recID_Detection = '119736'
) AND 
(recID_Detection = '119740' 
))
OR
((
recID_Detection = '113177' OR recID_Detection = '119732' OR recID_Detection = '119740'
) AND 
(recID_Detection = '119736' 
))
OR
((
recID_Detection = '113177' OR recID_Detection = '119736' OR recID_Detection = '119740'
) AND 
(recID_Detection = '119732' 
))
OR
((
recID_Detection = '119732' OR recID_Detection = '119736' OR recID_Detection = '119740'
) AND 
(recID_Detection = '113177' 
))
GROUP BY transmitter
;

即使没有 GROUP BY 并且甚至没有时间限制(它应该),这段代码也会导致一个空集(它不应该),所以我确信我做了一些不正确的事情,但我不能在文献中找到与我想做的类似的事情。

4

2 回答 2

2

由于您没有输入所有列的名称,我假设您的列名是datetime_Detection recID_Detection locID_Detection arrayID_Detection transmitterID_Detection

如果你不关心时间段,这会让你开始。

SELECT transmitterID_Detection,COUNT(DISTINCT recID_Detection) AS countPings 
FROM detections GROUP BY transmitterID_Detection
HAVING COUNT(DISTINCT recID_Detection) >= 3
于 2013-09-16T22:25:39.523 回答
1

我们来看第一个子句:

(recID_Detection = '113177' OR recID_Detection = '119732'
    OR recID_Detection = '119736'
) AND (recID_Detection = '119740')

子句的第一部分可以是真的,也可以是第二部分。不可能两者都为真,因此该子句始终为假。所有其他子句都以类似的方式构建,并且始终为 false,因此您永远不会使用此查询获得任何匹配项。

于 2013-09-16T22:13:12.620 回答