读书人

sql server 里面的包含如何写

发布时间: 2012-05-20 16:03:12 作者: rapoo

sql server 里面的包含怎么写?
字段A 字段B
A结束
A开始
A开始
A开始
A开始
A开始
B开始
B开始
B开始
C开始
C开始
C开始
C开始

语句需要把字段A对应的字段B中不包含 结束的对应的记录集提取出来,
结果如下:



B开始
B开始
B开始
C开始
C开始
C开始
C开始


[解决办法]

SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([字段A] varchar(1),[字段B] varchar(4))insert [test]select 'A','结束' union allselect 'A','开始' union allselect 'A','开始' union allselect 'A','开始' union allselect 'A','开始' union allselect 'A','开始' union allselect 'B','开始' union allselect 'B','开始' union allselect 'B','开始' union allselect 'C','开始' union allselect 'C','开始' union allselect 'C','开始' union allselect 'C','开始'select * from test awhere not exists(select 1 from test b    where a.字段A=b.字段A and b.字段B='结束')/*字段A    字段BB    开始B    开始B    开始C    开始C    开始C    开始C    开始*/ 

读书人网 >SQL Server

热点推荐