0

在 Ms Access 中,我可以创建一个名为“CustomerList”的查询,其中包含以下数据:

CustomerName, City, Revenue

然后我可以创建另一个查询,例如“CustomerCount”,如:

Select count(*) as Tot
from CustomerList   ( <<<- is a query name)
where CustomerList.City

此查询基于另一个查询。可以在 MYSQL 中做同样的事情吗?

谢谢

4

4 回答 4

3

是的,像这样

Select count(*) as Tot
from
(
  select City from some_table
) x
where x.City = 'NYC'

您必须给子查询起别名。

于 2013-10-11T13:38:43.117 回答
3

您可以创建一个VIEW

AVIEW就像一张桌子,但实际上是一个或多个桌子上的选择。

http://dev.mysql.com/doc/refman/5.0/en/create-view.html

于 2013-10-11T13:39:29.960 回答
0

您需要City在嵌套查询中命名一列或别名您只能这样做::

Select count(*) as Tot
from 
/*
select City,..... your query



*/

CustomerList   where CustomerList.City
于 2013-10-11T13:39:31.647 回答
0

您可以使用子查询来执行此操作。

select count(*) as Tot

from ( 
  select City from some_table
) c

where c.City = 'YOURCITY'

c在这种情况下,是子查询的别名。

于 2013-10-11T13:41:58.267 回答