执行sql:select cardno,name from cardtable where cardno not in (select cardno from cardtable where name='C');嵌套一个子查询来查找包含name包含C的cardno,然后再根据查询条件把cardno不包含的剔除掉。
运行如下:
扩展资料
sql的嵌套查询包括hen多的子查询,in的子查询、带比较运算符的子查询、带any/all的子查询、带exists的子查询以及基于派生表的子查询,这些查询嵌套使用可以达到强大的功能,比如筛选,过滤,排序,去重等等。
参考资料:W3C官网-SQL SELECT 语句
命令如下:
select * from table1 where patindex('%关键字%' , aa) = 0
select * from table1 where charindex('关键字' , aa) = 0
select * from table1 where aa like '%关键字%'
可以这样实现
select * from cardtable where cardno not in(select cardno from cardtable where name = 'C')
或
select * from cardtable a where not exists(select * from cardtable b where a.cardno = b.cardno and b.name = 'C')
select cardno ,name from cardtable where cardno not in (select cardno from cardtable where name like ‘%c%’
)
select * from cardtable where cardno not in(select cardno from cardtable where name = 'C')