If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > group by with datetime datatype

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-02, 23:07
mchih mchih is offline
Registered User
 
Join Date: Nov 2002
Posts: 98
group by with datetime datatype

I am trying to see a list of total log records, grouped by month:

select month(date),count(*)
from playcount
where year(date) = year(today)
group by month(date);

this gives me a syntax error
it appears the group by statement is not valid
i tried just "group by date", it worked but it's not what i wanted.

any suggestions?

TIA

Mark
Reply With Quote
  #2 (permalink)  
Old 11-25-02, 23:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
did you actually define a column called date? that's a reserved word and may be the source of your problem

rudy
Reply With Quote
  #3 (permalink)  
Old 11-25-02, 23:41
mchih mchih is offline
Registered User
 
Join Date: Nov 2002
Posts: 98
doesn't appear to be the case (tho your point is valid... i would never use date as an attribute name :P)

the following query also has a syntax error:

select month(playdate), count(*) from daily_prog
where year(playdate)=year(today)
group by month(playdate);
Reply With Quote
  #4 (permalink)  
Old 11-26-02, 00:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
well, i've never actually used informix, but i know where the docs are

try GROUP BY 1

see Using Select Numbers

rudy
Reply With Quote
  #5 (permalink)  
Old 11-26-02, 00:21
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
You can also do it by derived columns -

select month(playdate) test1, count(*) from daily_prog
where year(playdate)=year(today)
group by test1;
Reply With Quote
  #6 (permalink)  
Old 11-26-02, 01:01
mchih mchih is offline
Registered User
 
Join Date: Nov 2002
Posts: 98
you guys are great help!

tho for some reason rnealejr's solution would not work. It seems informix doesn't recognize alias in group by clause either.

Mark
Reply With Quote
  #7 (permalink)  
Old 11-26-02, 16:11
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
You are correct - for some reason I thought you were using an order by. Derived columns work for order by but not for group by.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On