本文介绍了仅选择个别记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表格

custno, type, color
A1234, B, Red
A1234, C, Blue
A1277, B, Red
A1288, A, Black
A1288, B, Red
A1289, A, Black

我只需要检索只找到一次的唯一记录A1277和A1289。

I need to retrieve only the unique records A1277 and A1289 that are only found once.

推荐答案

这将在结果列表中显示 custNO

This will display the custNO on the result list,

SELECT  custNo
FROM    tableName
GROUP   BY custNO
HAVING  COUNT(*) = 1

但是如果你想获得整行,

but if you want to get the whole row,

SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT  custNo
            FROM    tableName
            GROUP   BY custNO
            HAVING  COUNT(*) = 1
        ) b ON a.custNo = b.custNo





  • 这篇关于仅选择个别记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 20:01