0

I am getting min and max dates from text column with query which good people helped me to get there like this :

SELECT max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')),
min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY'))
FROM table_name;

How can I get COUNT of all matched rows between and including min and max dates (written in text column)?

2
  • 2
    This schema makes me want to cry. A really good start would be to prepare, adapt your queries, and when you're ready do an ALTER TABLE table_name ALTER COLUMN mydatetext TYPE date USING (to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) to turn this into a real date column you can work with sanely. Commented Aug 12, 2013 at 12:40
  • actually COUNT of all matched rows between and including min and max dates is just count(*) :) Commented Aug 15, 2013 at 19:55

1 Answer 1

0

All you really need to do is:

SELECT count(*), max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')), min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) 
  FROM table_name;

Or maybe I misunderstood. Really, you should, if at all possible, move the date field to a date type. If you have to handle garbage input, use a view and an update trigger to do that.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.