請教一個問題:mysql中,我查詢語句select * from tableA where name='test' and age='18';然后我有一個name和age的list列表,分別通過這兩個條件去查詢,有什么比較方法可以查詢;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';···其中查出來的數據對應Java的一個實體。其中List表的大小為500-3000,數據表的記錄為每天8萬左右
5 回答

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

慕桂英4014372
TA貢獻1871條經驗 獲得超13個贊
select a.*
from tableA a
inner join list l on l.name=a.name and l.age=a.age
不行嗎?

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