根据下表,我想选择与多个'SUB_CODE'相关联的'CODE'的行。
+------+------------+-------------+
| DIV | CODE | SUB_CODE |
+------+------------+-------------+
| 11 | 1000 | 1212 |
| 11 | 1000 | 1213 |
| 11 | 1000 | 3434 |
| 11 | 1000 | 1000 |
| 11 | 1000 | 3000 |
| 11 | 3000 | 1213 |
| 11 | 2000 | 1212 |
| 20 | 1500 | 5656 |
| 20 | 1500 | 1213 |
+------+------------+-------------+
对于上表,结果应为
+------+------------+-------------+
| DIV | CODE | SUB_CODE |
+------+------------+-------------+
| 11 | 1000 | 1212 |
| 11 | 1000 | 1213 |
| 11 | 1000 | 3434 |
| 11 | 1000 | 1000 |
| 11 | 1000 | 3000 |
| 11 | 1500 | 5656 |
| 11 | 1500 | 1213 |
+------+------------+-------------+
这就是我尝试的,我的结果如何失败。
Select CODE from TABLE_NAME where (count(SUB_CODE) > 1);
答案 0 :(得分:1)
答案 1 :(得分:0)
尝试这个:
Select `DIV`, `CODE`, `SUB_CODE` from TABLE_NAME GROUP BY `SUB_CODE`