SQL Server查询(尝试在中获取唯一结果) [英] Sql Server Query ( trying to get the unique result in )

查看:162
本文介绍了SQL Server查询(尝试在中获取唯一结果)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个表名称customer,它具有字段customerid,groupid,我想找到在groupid = 6中不存在的唯一的customerid.

一个客户可以出现在一组或多个组中,例如customerid=2出现在(6,7,8,9)等中.

我写了查询,但是没有用.

There is a table name customer and it have field customerid, groupid and i want to find the unique customerid who is not present in the groupid=6.

one customer can present in the one group or so many group, like customerid=2 is present in (6,7,8,9) etc..

I write the query but it is not working.

select * from customer where groupid1 !=6;


请帮助我.....


please help me.....

推荐答案

select distinct customerid from customer where groupid <> 6


从不在其中customerid的客户中选择customerid(从GroupID = 6的客户中选择coustomerid)
select customerid from customer where customerid not in ( select coustomerid from customer where GroupID=6 )


这篇关于SQL Server查询(尝试在中获取唯一结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆