April 16th, 2012, 09:30 AM
Is it possible to use two aggregate SQL function together
i am trying to use two aggregate functions ( at the same time) on an SQL query; i am not sure if this is possible.
i will explain;
i have a loggin script that records ,in UNIX time stamp, the exact time a member logs into the site. this is stored in a
MYSQL table called ;
in a column called
i now wish to receive three things from this table
1. the number of times the user has logged in . COUNT ( login_time)numberlogins
2. the last time occassion when the user logged in. MAX ( login_time ) lastlogin
3. the exact time that the user logged in. FROM_UNIXTIME( login_time )time
In my SQL query i obviously first have to do a 'GROUP BY' of the loggin times, and then use the aggregate functions listed above. i am clear on this point.
my question relates to part 3 of the above list, i.e obtaining the exact time of the last login. To get the time, i presume that i must convert the data ( that was obtained from the Max ( ) function) and convert this into a date format.
i tried to do the following 'doubling up' of two functions but it did not work
FROM_UNIXTIME (lastlogin, '%D %b %y' ( MAX ( login_time )lastlogin )time_loggin
i also tried the following;
FROM_UNIXTIME (lastlogin, '%D %b %y' )time_loggin
is it possible to combine these two agrregrate functions?
if not, how can i convert the data obtained from the
Max () function into a date
April 16th, 2012, 12:31 PM
by the way, i've moved your thread to the mysql forum
FROM_UNIXTIME( MAX(lastlogin), '%D %b %y' ) AS time_loggin
April 21st, 2012, 12:53 PM
hello. perfect. it works
its perfect.it works.
thank you to r937 for his kind assistance