2

我发现的最接近我正在寻找的东西是,所以我将使用它作为示例

MySQL:选择除列之外只有唯一值的行

给定这个数据集

+----+--------------+-------------+------+------+-------+-----+
| 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 |
+----+--------------+-------------+------+------+-------+-----+

我只想返回

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

因为它是唯一唯一的行

这可以用mysql吗?

4

3 回答 3

10
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
于 2012-12-19T14:52:36.223 回答
1

group by与_having count(*) = 1

于 2012-12-19T14:52:16.613 回答
1

尝试这个:

SELECT * FROM temptbl 
GROUP BY satellite_id, att_type_id, time, roll, pitch, yaw 
HAVING COUNT(*) = 1;
于 2012-12-19T14:55:11.470 回答