請(qǐng)教一個(gè)問題:mysql中,我查詢語句select * from tableA where name='test' and age='18';然后我有一個(gè)name和age的list列表,分別通過這兩個(gè)條件去查詢,有什么比較方法可以查詢;eg:select * from tableA where name='test' and age='18';select * from tableA where name='test1' and age='18';select * from tableA where name='test2' and age='20';select * from tableA where name='test2' and age='56';···其中查出來的數(shù)據(jù)對(duì)應(yīng)Java的一個(gè)實(shí)體。其中List表的大小為500-3000,數(shù)據(jù)表的記錄為每天8萬左右
5 回答

長(zhǎng)風(fēng)秋雁
TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
table A 添加一列名稱nameage 里面的值是 name和age的值合并 例如 test18
select * from tableA where nameage in ('test18','xxxxxx','xxxxxxx')
當(dāng)然你不添加列也行,自己sql拼下也行

慕桂英4014372
TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
select a.*
from tableA a
inner join list l on l.name=a.name and l.age=a.age
不行嗎?

忽然笑
TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
數(shù)據(jù)量不大的時(shí)候,可以這樣干。
SELECT * FROM tableA
WHERE (name, age) IN (
('test', 18),
('test1', 18),
('test2', 20),
('test2', 56))
但通過explain以上查詢會(huì)發(fā)現(xiàn),這種寫法是沒法用上索引的,所以查詢效率很低。
添加回答
舉報(bào)
0/150
提交
取消