当前位置:首页 » 编程语言 » sql等于多个值

sql等于多个值

发布时间: 2022-08-08 08:17:32

sql 语句查找某字段等于多个可能值

2种写法
1)
SELECT * FROM `order_status` WHERE order_status_id= 3 OR order_status_id = 16
2)
SELECT * FROM `order_status` WHERE order_status_id IN (3, 16)

Ⅱ 求问SQL查询同时满足多个值的数据。

可以把语句改成:
SELECT member_id FROM 会员表 EXISTS(SELECT proct_id from 订单产品表,订单表 where 订单表.member_id = 会员表.member_id and 订单表.order_id=订单产品表.order_id and
(
订单产品表.proct_id = 1
and 订单产品表.proct_id = 2
and 订单产品表.proct_id = 3
and 订单产品表.proct_id = 4
and 订单产品表.proct_id = 5
)

Ⅲ 请教SQL写法,同时满足多个值的数据。

你的代码中“订单产品表.proct_id in( 1,2,3,4,5 )”的意思是产品的ID属于这个集合就算满足条件。事实要满足5中产品都有。如果只有5中产品,有一种方法可以用count函数,COUNT(DISTINCT column_name) =5,如果产品数目大于5的话,如果有N种,那就必须用类似这种句型select member_id FROM 会员表,会员表 会员表1 ,会员表 会员表2 ,会员表 会员表3,…… where …… and where(select (cout (distinct proct_id)=5)) 。给你个列子:
1、检索所有课程都选修的的学生的学号与姓名
select xh,xm from s where not exists
(select * from c
where not exists
(select * from e
where xh=s.xh and kh=c.kh
) )
2、检索同时选修了课程“”和课程“”的学生学号和姓名
select distinct s.xh,s.xm from s,e,e f
where e.xh=f.xh and s.xh=e.xh and e.kh='08305001' and f.kh='08305002'
e f 表示与e表相同数据的一张表分f。kh表示课程ID。

Ⅳ SQL语句如何等于多个子查询的值,如图所示,谢谢各位大神,写存储过程。

不用存储过程,一个sql语句搞定

创建表及数据

createtablea
(idint,
avarchar2(3),
bvarchar2(100));
createtableb
(idint,
cvarchar2(3),
dvarchar2(100));
createtablec
(idint,
evarchar2(3),
fvarchar2(100));

insertintoavalues(1,'001',null);
insertintoavalues(2,'002',null);
insertintoavalues(3,'003',null);
insertintoavalues(4,'004',null);
insertintoavalues(5,'005',null);
insertintoavalues(6,'006',null);
insertintobvalues(1,'001','chao');
insertintobvalues(2,'001','qian');
insertintobvalues(3,'002','sun');
insertintobvalues(4,'003','li');
insertintobvalues(5,'003','zhou');
insertintocvalues(1,'001','wu');
insertintocvalues(2,'002','zhen');
insertintocvalues(3,'003','wang');
commit;

执行

updateat1sett1.b=
(selectt2.col2
from
(selectcol1,replace(wm_concat(col2),',','/')col2
from
(select1id,ccol1,dcol2fromb
unionall
select2id,ecol1,fcol2fromc)t
groupbycol1)t2
wheret1.a=t2.col1);

结果

这个wm_concat你要是用不了,就改成sys.wm_concat,再不行,你就把你当前用户赋一个dba权限

Ⅳ sql查询字段中所有等于某些值的数据

不知道这样可以不,看你的数据库应该是mysql

创建表插入数据

createtabletest
(channel_idint,
app_idvarchar(10));


insertintotestvalues(1,'a001');
insertintotestvalues(2,'a001');
insertintotestvalues(2,'a002');
insertintotestvalues(3,'a002');
insertintotestvalues(4,'a002');
insertintotestvalues(3,'a003');
insertintotestvalues(4,'a003');
insertintotestvalues(5,'a003');
insertintotestvalues(6,'a003');
insertintotestvalues(7,'a004');

执行:

SELECT
app_id,
group_concat(channel_id)
FROM
test
WHERE
channel_idIN(1,2,3,4,5,6,7)
GROUPBY
app_id

结果:

看结果的话,就能看出每个app_id对应了哪些channel_id了,然后想筛选多个的话,直接嵌套一层,然后like '%,%'就可。

Ⅵ sql查询 怎么查询某一列同时等于多个值的那几行。

4行变成1行?
如果用
SQL
Server
的话,可以用一种很
诡异的方法:
SELECT
DISTINCT
','
+
SALE_ITEM
FROM
SALE_REPORT
FOR
XML
PATH('')
楼主可以测试一下,最后用一个
FOR
XML
PATH('')
就好。
我上面的
SQL
执行结果为:
,C,A,B

Ⅶ SQL语句查询条件“一个字段=多个值”怎么写

select * from otim where sheetid in(1,2,3)

Ⅷ SQL函数返回多个值的问题

--楼主 你这个问题 还有点小复杂 因为返回值不只一个 所以只能用表变量了
create function getinv_name(@inv_code nvarchar(50))
RETURNS @TempTable table(inv_name nvarchar(50) ,
inv_model nvarchar(50))
AS
begin
insert into @TempTable(inv_name,inv_model)
select inv_name,inv_model from mate_inv_dict where inv_code=@inv_code
return
end
--这里需要提醒楼主的是 因为返回的是表变量 所以不能像返回变量那样调用这个函数
--给你写个例子吧
select * from getinv_name('100001')
--有什么疑问可以找我
--如果满意 请采纳

Ⅸ 如何用SQL查询某一列中分别等于几个值的个数

用 in
SELECT * FROM `order_status` WHERE order_status_id in(3,6)

热点内容
国密算法获取 发布:2024-05-04 16:38:24 浏览:69
脚本精灵荒野乱斗 发布:2024-05-04 16:28:33 浏览:519
刚到的笔记本怎么看配置 发布:2024-05-04 16:26:58 浏览:3
苹果7怎么给支付宝加密码 发布:2024-05-04 16:13:12 浏览:405
sql培训视频 发布:2024-05-04 16:00:59 浏览:263
极无双平新服务器什么时候出 发布:2024-05-04 15:50:47 浏览:662
c语言千分数 发布:2024-05-04 15:46:31 浏览:345
数据库no 发布:2024-05-04 15:38:00 浏览:221
ionic编译android 发布:2024-05-04 15:20:45 浏览:489
云服务器在哪买 发布:2024-05-04 15:19:18 浏览:86