Find Unique Values in Column CC of Table T
This query aims to find rows in table 'T' where the data in column 'CC' appears only once. Here's how to achieve this using SQL:
SELECT *
FROM T
WHERE CC IN (SELECT CC FROM T GROUP BY CC HAVING COUNT(*) = 1);
Explanation:
- SELECT * FROM T: This selects all columns and rows from the table 'T'.
- WHERE CC IN (SELECT CC FROM T GROUP BY CC HAVING COUNT(*) = 1): This filters the result to include only rows where the value in column 'CC' appears only once.
- SELECT CC FROM T GROUP BY CC: This subquery groups the table by column 'CC', effectively counting the occurrences of each distinct value in 'CC'.
- HAVING COUNT(*) = 1: This clause filters the grouped results to only include those where the count of occurrences for a particular value in 'CC' is equal to 1, meaning it appears only once in the table.
This query effectively identifies rows in the table where the data in column 'CC' is unique. You can adapt this approach for different tables and columns as needed.
原文地址: https://www.cveoy.top/t/topic/kwUO 著作权归作者所有。请勿转载和采集!