我有一个MySQL查询:
select *
from traffic
group
by type
, date
, address
having count(date and type and address) > 3
and status = 0
我想选择输入相同类型,日期,有计数地址(日期和类型和地址)> 3和状态= 0的不同用户的所有详细信息。
这是表格
traffic
slno | username | lat | longi | message | dat | time | type | address | status
上述查询有效,但如果同一用户输入的数据超过三次,我的查询会显示结果。我希望在不同的用户输入相同的流量数据时看到结果。
+==========+
| traffic |
+==========+
| slno |
| username |
| lat |
| longi |
| message |
| dat |
| time |
| type |
| address |
| status |
+----------+
答案 0 :(得分:0)
选择超过3个不同用户拥有相同流量数据的流量记录:
SELECT *
FROM `traffic`
WHERE `status` = 0
GROUP BY `type`, `date`, `address`
HAVING COUNT(DISTINCT `username`) > 3
如果您想选择相应的用户:
SELECT DISTINCT t.*
FROM `traffic` t
INNER JOIN (
SELECT *, COUNT(DISTINCT `username`)
FROM `traffic`
WHERE `status` = 0
GROUP BY `type`, `date`, `address`
HAVING COUNT(DISTINCT `username`) > 3
) x
ON t.`type` = x.`type`
AND t.`date` = x.`date`
AND t.`address` = x.`address`
答案 1 :(得分:0)
你的意思是这样的:
select username, date, type, address
from traffic
where status = 0
group by username, date, type, address
having count(date) > 3
and count(type) > 3
and count(address) > 3