我有一個(gè) ids 列表,我想使用這個(gè)列表作為參數(shù),如下所示:list_id = ['4833', '43443', '431431']qry = f"""SELECT c.nm_cnae as Nome_CNAE FROM cnae as c WHERE c.cod_cnae = '{list_id}'"""resultado_busca = cosmosengine.query('cnae', qry)resultado_busca = list(resultado_busca)我應(yīng)該怎么做這個(gè)工作?我正在使用 azure cosmosdb
1 回答

嗶嗶one
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
假設(shè)您想查找列表中具有 id 的所有內(nèi)容,則為:
list_id = ['4833', '43443', '431431']
qry = f"""SELECT
c.nm_cnae as Nome_CNAE
FROM cnae as c
WHERE c.cod_cnae IN ({','.join(list_id)})"""
resultado_busca = cosmosengine.query('cnae', qry)
resultado_busca = list(resultado_busca)
這在sql中使用IN運(yùn)算符:https ://www.w3schools.com/sql/sql_in.asp
','.join(list_id)創(chuàng)建一個(gè)字符串,其中每個(gè)值都用逗號分隔。
添加回答
舉報(bào)
0/150
提交
取消