一个很扭结的查询语句

一个很纠结的查询语句

一个表 

name store两列 有n条数据

 要得到name列中名字相同的行中store列值唯一的

比如

name store

a 11

a 22

a 11

a 33

b 44

b 55

b 44

c 66

d 77

d 77

要得到  

a 22

a 33

b 55

c 66

行  

请教各位大神,这个sql语句怎么写 尽量短点的



mysql> select name,store from tt group by store having count(*)=1;

+——+——-+

| name | store |

+——+——-+

| a | 22 | 

| a | 33 | 

| b | 55 | 

| c | 66 | 

+——+——-+

4 rows in set (0.02 sec)




mysql> select name,store from (select name,store,count(*) total from tt group by store) t where total=1;

+——+——-+

| name | store |

+——+——-+

| a | 22 | 

| a | 33 | 

| b | 55 | 

| c | 66 | 

+——+——-+

4 rows in set (0.02 sec)

看看哪个快。

一个很扭结的查询语句

相关文章:

你感兴趣的文章:

标签云: