MySQL choice within selection

I'm not even sure if the title is correct, sorry if not!

I have a MySQL database that stores information about Wi-Fi devices collected from several access points.

Below is my instruction SELECT, which returns all devices found within 1 hour:

SELECT mac 
  FROM TBLWiFi 
GROUP BY 
       mac 
HAVING COUNT( mac ) >1 
       AND TIMESTAMP >= DATE_SUB( NOW( ) , INTERVAL 1 HOUR )
)

The results look like this:

╔═══════════════════╦══════════════════╦═════════════╗
β•‘ mac               β•‘ timestamp        β•‘ reportedby  β•‘
╠═══════════════════╬══════════════════╬═════════════╣
β•‘ B0:02:94:1D:3B:43 β•‘ 21/03/2014 12:27 β•‘ AP-3c9b33d0 β•‘
β•‘ C0:3E:0F:0F:2D:EB β•‘ 21/03/2014 12:37 β•‘ AP-3c9b33d0 β•‘
β•‘ 64:70:02:29:16:AE β•‘ 21/03/2014 12:32 β•‘ AP-3c9b33d0 β•‘
β•‘ B0:02:94:1D:3B:43 β•‘ 21/03/2014 12:46 β•‘ AP-5c9b33d0 β•‘
β•‘ B4:F0:AB:C2:F6:92 β•‘ 21/03/2014 12:46 β•‘ AP-3c9b33d0 β•‘
β•‘ 00:26:AB:F1:7C:EE β•‘ 21/03/2014 12:45 β•‘ AP-5c9b33d0 β•‘
β•‘ B0:02:94:1D:3B:43 β•‘ 21/03/2014 12:45 β•‘ AP-4c9b33d0 β•‘
β•‘ 1C:C1:DE:6A:90:47 β•‘ 21/03/2014 12:56 β•‘ AP-4c9b33d0 β•‘
β•‘ B4:F0:AB:C2:F6:92 β•‘ 21/03/2014 13:02 β•‘ AP-3c9b33d0 β•‘
β•‘ 00:26:AB:F1:7C:EE β•‘ 21/03/2014 13:07 β•‘ AP-4c9b33d0 β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Now I want to know which devices ( mac) have been registered with more than one access point ( reportedby).

I am in a flat rotation, my mind has completely disappeared. Any help would be appreciated.

+4
source share
2 answers

First, your request should look like this:

SELECT mac 
FROM TBLWiFi 
WHERE TIMESTAMP >= DATE_SUB( NOW( ) , INTERVAL 1 HOUR )
GROUP BY  mac 
HAVING COUNT( mac ) > 1 ;

having timestamp timestamp mac. .

, having :

HAVING COUNT(mac) > 1 and
       COUNT(DISTINCT reportedby) > 1;

, reportedby, , :

HAVING COUNT(DISTINCT reportedby) > 1;
+2
SELECT mac 
  FROM TBLWiFi 
GROUP BY 
       mac 
HAVING COUNT( reportedby ) >1 
       AND TIMESTAMP >= DATE_SUB( NOW( ) , INTERVAL 1 HOUR ))

, COUNT (mac) > 1... ... SELECT SELECT JOINT , 2 ... , ...: -)

0

Source: https://habr.com/ru/post/1532833/


All Articles