MySQL计数不同,其中五个接收器中的三个接收器用于三角测量

时间:2013-09-16 22:05:37

标签: mysql select

我有一个无线电发射器检测列表,为了处理三角测量数据,我需要确保该站点有三个或更多接收器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,甚至没有时间限制(它应该),所以我确信我做了一些不正确的事,但我找不到类似于我想在文献中做的事情。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

让我们看看第一个条款:

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

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