1.用select ...,count(...) as field1... group by field1 order by field1
不行吗?
2.用 EXTRACT(YEAR FROM date1) AS YY ...group by yy.. 按年
EXTRACT(MONTH FROM date1) AS MM,...group by mm.. 按月
按周可能要用计算字段先统计。
标准SQL的from语句后面的表可以是一个子查询,因此可以用这个特征在一条语句写出这个查询,设有表a
aa
1
2
2
3
3
以下查询返回
2
3
select a1.aa from (select count(aa) as a1_cn, aa from a group by aa ) as a1
where a1_cn >= ( select max (cn ) from (select count(aa) as cn from a group by aa) as tmp )
SELECT MAX(T1)
FROM (SELECT COUNT(。。)T1 FROM 。。 GROUP BY 。。)
THIS SQL CAN RUN ON ORACLE OR DB2,
其他的我不知道。
OR
FUNCTION MAXVALUE:INTEGER
begin
WITH TQUERY。CREATE(NIL)do
begin
TYR
DATABASENAME := ‘。。’;
SQL。ADD(‘SELECT COUNT(。。)T1 FROM 。。 GROUP BY 。。’);
ACTIVE := TRUE;
RESULT :=0;
WHILE NOT EOFdo
begin
IF FIELDBYANME(‘T1’)。ASINTEGER > TEMPVALUE then
RESULT := FIELDBYANME(‘T1’)。ASINTEGER;
END;
FINALLY
FREE;
END
END;