[Lazarus] OT: SourceForge Removes Blanket Blocking

Flávio Etrusco flavio.etrusco at gmail.com
Tue Feb 9 00:12:45 CET 2010


If you really want three columns with counts for the two hardcoded
years, you could use subqueries:

with distinct_types (
  type
)
as (
  select distinct type from table
)
select
  dt.type,
  (
    select
      count(*) count_2008
    from table
    where (type = dt.type) and (extract(year from date) = 2008)
  ),
  (
    select
      count(*) count_2009
    from table
    where (type = dt.type) and (extract(year from date) = 2009)
  )
from distinct_types dt;

but perhaps the following is better since it's generic for all years
(and if needed you can still limit the years using a HAVING clause):

select
  a.type,
  extract(year from a.date) a_year,
  count(*)
from table a
group by 1, 2;




More information about the Lazarus mailing list