我有一个分支表:
+-------+-----------+--------+
| name | city | assets |
+-------+-----------+--------+
| cbi1 | bangalore | 5000 |
| cbi2 | bangalore | 8000 |
| cbi3 | katihar | 12000 |
| icici | purnia | 15000 |
| cbi4 | nasik | 18000 |
+-------+-----------+--------+
我需要找到资产大于班加罗尔任何分支的所有分支。
答案 0 :(得分:1)
select name from branch where city !='bangalore' and assets > (select min(assets) from branch where city = 'bangalore') ;
子查询select min(assets) from branch where city = 'bangalore'
将为所有banagalore
分支提供最低资产价值。
然后将它与表
没有子查询
select distinct(b1.name) from branch b1, branch b2 where b1.city !='bangalore' and b2.city ='bangalore' and b1.assets > b2.assets;
不使用子查询,您需要对该表进行自联接。