當前位置:首頁 » 編程語言 » 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-04-25 08:34:59 瀏覽:208
sql性能監視器 發布:2024-04-25 08:21:48 瀏覽:832
吃雞ak配置什麼最好 發布:2024-04-25 08:15:46 瀏覽:447
firefox緩存目錄 發布:2024-04-25 08:00:31 瀏覽:940
我的世界國服怎麼免費弄伺服器 發布:2024-04-25 08:00:16 瀏覽:539
javaapi源碼 發布:2024-04-25 07:51:15 瀏覽:606
怎麼在伺服器執行jmeter腳本 發布:2024-04-25 07:35:25 瀏覽:397
域名訪問https 發布:2024-04-25 07:16:56 瀏覽:414
javaie亂碼 發布:2024-04-25 07:07:15 瀏覽:602
php開發微信支付 發布:2024-04-25 06:57:38 瀏覽:317