查询与‘精益’在一个城市的供应商的供应商的号码、供应商名称及城市名;(用两种方式写,嵌套与非嵌套)
时间: 2024-03-02 07:52:29 浏览: 106
非嵌套写法:
```
SELECT s2.supplier_id, s2.supplier_name, s2.city
FROM suppliers s1, suppliers s2
WHERE s1.supplier_name = '精益' AND s1.city = s2.city AND s1.supplier_id != s2.supplier_id
```
嵌套写法:
```
SELECT supplier_id, supplier_name, city
FROM suppliers
WHERE city IN (
SELECT city
FROM suppliers
WHERE supplier_name = '精益'
)
AND supplier_name != '精益'
```
以上两种写法都是查询与名为‘精益’的供应商在同一城市的供应商的号码、供应商名称及城市名。其中,第一种写法使用了自连接,第二种写法使用了子查询。
阅读全文