来自两列的Fliter sql表 [英] Fliter sql table from two columns

查看:60
本文介绍了来自两列的Fliter sql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我我的sql表看起来像这样



Please help me My sql table look like this

Slno   HeadName    BankCode
1	Abc         Cash
2	Contra	   Bank1
3	Contra	   Cash
4	Xyz	   Cash
5	Contra	   Bank2
6	Contra	   Cash
7	Pqr	   Bank1





我的要求是过滤table.i需要从HeadName删除'Contra'并且BankCode不等于='现金'即删除slno no 2,5我想要的所有其他行检索所有其他行



请帮助



我的表结构和样本数据如下所示/>




My requirement is to filter the table.i Need to remove the 'Contra' from HeadName and BankCode not equal='Cash' ie remove slno no 2,5 all other rows i would like to retrive all other rows

please help

My table structure and sample data is given below

CREATE TABLE [dbo].[sampletable2]( ID INT PRIMARY KEY , [HeadName] nvarchar, [BankCode] nvarchar )

Insert Into sampletable2 Values(1,'Abc','Cash'), Insert Into sampletable2 Values(2,'Contra','Bank1') Insert Into sampletable2 Values(3,'Contra','Cash') Insert Into sampletable2 Values(4,'Xyz','Cash') Insert Into sampletable2 Values(5,'Contra','Bank2') Insert Into sampletable2 Values(6,'Contra','Cash') Insert Into sampletable2 Values(7,'Pqr' ,'Bank1')

Select * from sampletable2

推荐答案





试试这个...

Hi,

Try this...
--Final  

insert into sampletable2 
SELECT * from yourtable
where id not in (SELECT id from yourtable WHERE 
BankCode in ('Bank2','Bank1') and headName = 'Contra'
 )





希望这会对你有所帮助。





干杯



Hope this will help you.


Cheers


这篇关于来自两列的Fliter sql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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