【发布时间】:2014-09-23 07:18:30
【问题描述】:
这些是我的桌子
表 1
- 价格
- city_category_id
- city_product_id
这里是三行"
price | city_category_id | city_product_id
------+------------------+--------------------------
1500 | CHDELCLAPTOPDELL | CHDELCLAPTOPDELLVOSTR8
1200 | CHDELCLAPTOPDELL | CHDELCLAPTOPDELLVOSTR816
1000 | CHDELCLAPTOPDELL | CHDELCLAPTOPDELLVOSTR816
在这里我必须首先找到不同的产品名称,然后选择不同元素的最低价格。我希望输出为CHDELCLAPTOPDELLVOSTR816 and 1200 and CHDELCLAPTOPDELLVOSTR816 and 1000。
查询
select min(price)
from sellers_product
where city_product_id=
(
select distinct city_product_id
from sellers_product
where city_category_id='CHDELCLAPTOPDELL'
)
错误
我知道为什么会出现此错误,因为子查询返回的行超过 1 行,但有没有办法仅使用 1 个查询来获得所需的输出。
【问题讨论】:
-
将
city_product_id=更改为city_product_id IN ( -
你的 rdbms 是什么? mysql还是sql server?
-
为什么标签中同时包含mysql和mssql?
-
@Abhik 它只返回 1 个不同的价格和 city_product_id。我想要两个
-
从子查询中删除然后
标签: mysql sql sql-server