我用的mysql数据库,需要用到 where in 。有一个Company表,一个Product表。
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
LIMIT 1
这一句从Product表返回商品数量最多的P_Company(企业名称)没问题,
下面这句加上了where in 为什么就不行了呢?
select * from product where P_Company IN
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
LIMIT 1
)
select * from product where P_Company IN
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
where rownum
select * from product where P_Company IN
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
where rownum<2
)
还是不行
[SQL] select * from product where p.P_Company IN
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
LIMIT 1
)
[Err] 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
这个版本的MYSQL不支持?
select * from product where P_Company IN
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
LIMIT 1
)
换一种思路:
select * from product p HAVING p.P_Company=
(
SELECT 企业名称 FROM
(
select p.P_Company AS 企业名称,COUNT(p.P_Company) AS 产品总数 from product p GROUP BY p.P_Company ORDER BY 产品总数 DESC
)K
LIMIT 1
)