如何在sql表中进行AND操作? [英] How to do AND Operation in sql Table?

查看:71
本文介绍了如何在sql表中进行AND操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的sql表....



 Id Bag Tapee Band鞋刀吉他手表雨伞锤
1 1 0 1 1 0 1 1 1 0
2 0 0 1 1 0 1 1 0 0
3 0 0 1 1 0 0 0 0 0



i想做 AND操作使用transcation id ....

例如我做 AND操作 transcation id 1和2 表示

我们可以得到0 0 1 1 0 1 1 0 0 .....

如何做到这一点和所有Transcation id的操作如transcation id 1& 2,1& 3,1& 2& 3

如何在sql或c#.net

解决方案中执行此操作

  create   table  #bitoprt(id  int   identity  1  1 ),包,tapee ,band ,刀,吉他,观看,伞,锤
insert into #bitoprt
values
0 1 1 0 1 1 1 0 ),
0 1 1 0 1 1 0 0 ),
0 1 1 0 0 0 0 0


select (bt.bag& bt1.bag)bag,(bt.band& bt1.band)band,(bt.guitar& bt1.guitar)guitar
,(bt.hammer& bt1.hammer)hammer,(bt.knife& bt1.knife)刀
,(bt.tapee& bt1.tapee)tapee,(bt.umbrella& bt1.umbrella)伞,(bt.watch& bt1.watch)观看
来自 #bitoprt bt
join #bitoprt bt1 on bt.id = bt1.id + 1
其中 bt.id in (< span class =code-digit> 1 , 2


您好,



尝试以下sql



 选择 min(bag),min(Tapee),min(Band),min(shoes),min(knife),min(guitar),min(watch),min(umbrella),min (锤子)
来自 [dbo]。[transcation] 其中 id in 1 2





答案是

  0   0   1   1   0   1   1   0   0  


这里是如何在SQL Server中执行此操作



&安培; (按位AND)(Transact-SQL) [ ^ ]

I have sql table like below....

Id	Bag	Tapee	Band	shoes	knife	guitar	watch	umbrella hammer
1	1	0	1	1	0	1	1	1	  0
2	0	0	1	1	0	1	1	0	  0
3	0	0	1	1	0	0	0	0	  0


i wanna do AND Operation using transcation id....
For example i do AND Operation for transcation id 1 and 2 means
we can get 0 0 1 1 0 1 1 0 0.....
How to do like this AND Operation for all Transcation id like transcation id 1&2, 1&3,1&2&3
How to we perform this operation in sql or c#.net

解决方案

create table #bitoprt(id int identity(1,1),bag bit,tapee bit,band bit,knife bit,guitar bit,watch bit,umbrella bit,hammer bit)
insert into #bitoprt
values
(0, 1,  1,  0,  1,  1,  1,    0),
    (   0,  1,  1,  0,  1,  1,  0,    0),
    (   0,  1,  1,  0,  0,  0,  0,    0)


select (bt.bag & bt1.bag)bag,(bt.band & bt1.band)band,(bt.guitar & bt1.guitar)guitar
,(bt.hammer&bt1.hammer)hammer,(bt.knife&bt1.knife)knife
,(bt.tapee &bt1.tapee)tapee,(bt.umbrella&bt1.umbrella)umbrella,(bt.watch&bt1.watch)watch
from #bitoprt bt
join #bitoprt bt1 on bt.id = bt1.id+1
where bt.id in(1,2)


Hi,

Try below sql

select min(bag),min(Tapee),min(Band),min(shoes),min(knife),min(guitar),min(watch),min(umbrella),min(hammer)
 from [dbo].[transcation] where id in(1,2)



Answer is

0	0	1	1	0	1	1	0	0


here is how to do it in SQL Server

& (Bitwise AND) (Transact-SQL)[^]


这篇关于如何在sql表中进行AND操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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