我正在使用单个 sql 从同一个表中的两个不同行中选择数据。
"id" "borrowMax" "holder" "category" "country"
"1" "2" "0" "3" "US"
"2" "0" "1" "10" "US"
我正在努力解决这个问题。
select id, holder from mytable where id = 2
select borrowMax from mytable where id = (
holder from the above select, in this case it's 1
) and category = 3
在网上查看示例后,我的做法是
SELECT col1.id, col1.holder, col2.borrowMax
FROM collection_db col1
JOIN collection_db col2
ON col2.holder = col1.id
WHERE col1.id = 2 //Here, 2 is the value supplied by me
AND col2.category = 3
当然,这行得通。但由于这是我自己拼凑的东西,我有我的怀疑。怎么会you
做这样的事情?我在正确的轨道上吗?(我确定我不是)。