Link to home
Start Free TrialLog in
Avatar of crishna1
crishna1Flag for United States of America

asked on

group by

select to_date('2004/02/11 07:32:00', 'YYYY/MM/DD HH24:MI:SS'),count (*) from XXX group by XXX;

How can i  reference the group by on a date column? Please help!
Avatar of reginab
reginab

Use Functions like YEAR() or DatePart() and group by this.
An examle:
SELECT YEAR(Date_Column),SUM(Sum_Column) FROM tbl GROUP BY YEAR(Date_Column)
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> what DB engine are you using?

This is a good question, as different databases use different flavours of SQL...
Is a good question, because of internal functions or anything. If you are using PL/SQL or T-SQL the functions changes. For example in MS T-SQL there are several options that in Sybase T-SQL doesn't work.
Besides the question doesn't have to be a "good" one... is only a question. In generarlly speaking the questions are only for answer them, not judging them.
Venabili,

I object... because I tried the TimYates solution in Sybase and doesn't seem to work.
The mine works in Sybase(T-SQL).

-tom
Mine will work in Oracle and Postgres (I think)
It's  a split then...
Tim in PL/SQL, mine T-SQL

-tom
Doesn't sybase have the "AS" keyword then?
Yes it has...

But you can not referer to an AS field in a group by clause. You have to be explicit.

-tom
Fair enough :-)

A split between me and you seems more than fair then :-)

Tim
by the way, this question does not make sense.
What is the author trying to do anyway ?? - group-by column has to be referenced in the 'select' part!

According to the ANSI, there are 2 syntaxes for group-by clause:
  1) use full column name : group by col_name
  2) use relative number of the column in select clause: group by 1


The question is about how to do a Group By clause, and the answers are right for T-SQL and PL/SQL

-tom