首页 > 解决方案 > 最大子查询

问题描述

select substr(phone,0,3) as area_code
from customer
where (select max(count(area_code)) 
         from customer);

为什么这里有错误?怎么修?它说缺少表达..

标签: sql

解决方案


整个select max() ...部分返回一个值,但在whereclausule 之后你应该有类似where something = 1. 我只能猜测你想用这个查询实现什么,但它可能应该是这样的:

select substr(phone,0,3) as area_code from customer 
where area_code in (select max(substr(phone,0,3)) from customer);

PS看这里


推荐阅读