简体   繁体   English

MySQL-仅选择列具有唯一值的行

[英]Mysql - Select only rows where column has unique value

The closest thing I found to what I am looking for is, so I will use it as an example 我找到的与我所寻找的最接近的东西是,所以我将以它为例

MySQL: Select rows that have only unique values except for a column MySQL:选择除列之外仅具有唯一值的行

Given this dataset 给定这个数据集

+----+--------------+-------------+------+------+-------+-----+
| ID | SATELLITE_ID | ATT_TYPE_ID | TIME | ROLL | PITCH | YAW |
+----+--------------+-------------+------+------+-------+-----+
|  1 |            1 |           1 | 2012 |  1.0 |   2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+
|  2 |            1 |           1 | 2012 |  1.0 |   2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+
|  3 |            1 |           1 | 2011 |  1.0 |   2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+

I would like to return only 我只想返回

+----+--------------+-------------+------+------+-------+-----+
| ID | SATELLITE_ID | ATT_TYPE_ID | TIME | ROLL | PITCH | YAW |
+----+--------------+-------------+------+------+-------+-----+
|  3 |            1 |           1 | 2011 |  1.0 |   2.0 | 1.3 |
+----+--------------+-------------+------+------+-------+-----+

because it is the only unique row 因为它是唯一的唯一行

Is this possible with mysql? mysql有可能吗?

SELECT 
    ID, 
    SATTELLITE_ID, 
    ATT_TYPE_ID, 
    TIME, 
    ROLL, 
    PITCH, 
    YAW 
FROM Table 
GROUP BY 
    SATTELLITE_ID, 
    ATT_TYPE_ID, 
    TIME, 
    ROLL, 
    PITCH, 
    YAW 
HAVING COUNT(*) = 1

group by having count(*) = 1使用group by

Try this: 尝试这个:

SELECT * FROM temptbl 
GROUP BY satellite_id, att_type_id, time, roll, pitch, yaw 
HAVING COUNT(*) = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM