恩,我的意思就是象wzh1215这位说的这样的,但是有一点不一样,我统计的count不是某一列,而是select count(*) from 表 where ....这样的,请问怎么写呢?
select max(counts) from ( select count(*) counts from 表 where .... union all select count(*) from 表 where .... union all select count(*) from 表 where .... ) tmp
( select count(*) counts from 表 where .... union all select count(*) from 表 where .... union all select count(*) from 表 where .... ) 表的别名
一个或多个派生表,这些派生表是 FROM 子句中的 SELECT 语句,以别名或用户指定的名称来引用这些派生表。FROM 子句中 SELECT 语句的结果集构成了外层 SELECT 语句所用的表。例如,下面的 SELECT 语句使用派生表查找是否有哪家书店备有 pubs 数据库中所有种类的书籍: SELECT ST.stor_id, ST.stor_name FROM stores AS ST, (SELECT stor_id, COUNT(DISTINCT title_id) AS title_count FROM sales GROUP BY stor_id ) AS SA WHERE ST.stor_id = SA.stor_id AND SA.title_count = (SELECT COUNT(*) FROM titles)
表的别名可以任一的,并不一定要数据库中有此表名! select max(counts) from ( select count(*) counts from 表 where 条件1 union all select count(*) from 表 where 条件2 union all select count(*) from 表 where 条件3 ) tmp --这样不是可以得到最大值的吗!
select max(count(field1),count(field2),count(field3)),max(sum(field1),sum(field2),sum(field3)) from 表
from
(
select count(*) counts from 表 where ....
union all
select count(*) from 表 where ....
union all
select count(*) from 表 where ....
) tmp
select count(*) counts from 表 where ....
union all
select count(*) from 表 where ....
union all
select count(*) from 表 where ....
) 表的别名
SELECT ST.stor_id, ST.stor_name
FROM stores AS ST,
(SELECT stor_id, COUNT(DISTINCT title_id) AS title_count
FROM sales
GROUP BY stor_id
) AS SA
WHERE ST.stor_id = SA.stor_id
AND SA.title_count = (SELECT COUNT(*) FROM titles)
select max(counts)
from
(
select count(*) counts from 表 where 条件1
union all
select count(*) from 表 where 条件2
union all
select count(*) from 表 where 条件3
) tmp
--这样不是可以得到最大值的吗!