当前位置: 代码迷 >> Sql Server >> sql server 里面的包含如何写
  详细解决方案

sql server 里面的包含如何写

热度:95   发布时间:2016-04-27 12:48:12.0
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    开始*/
  相关解决方案