SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get avg time on site by age ranges

    Hi,
    query time this morning ^^
    Is it right this query
    PHP Code:
    SELECT A.domain_id AS domain_id
    CASE 
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) <18
            THEN  
    '13-17'
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) >17 <25
            THEN  
    '18-24'
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) >24 <35
            THEN  
    '25-34'
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) >34 <45
            THEN  
    '35-44'
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) >35 <55
            THEN  
    '45-54'
        
    WHEN FLOOR( (TO_DAYSNOW( ) ) - TO_DAYSU.nascita ) ) / 365.25) >55 <65
            THEN  
    '55-64'
            
    ELSE  '65->'
            
    END AS field
    NULL AS subfield
    CASTA.access_start_datetime AS DATE ) AS DATE
    CASE 
        
    WHEN AVGTIMESTAMPDIFFMINUTE A.access_start_datetimeA.access_end_datetime ) ) <10
            THEN  
    '0-10'
        
    WHEN AVGTIMESTAMPDIFFMINUTE A.access_start_datetimeA.access_end_datetime ) ) >11 <21
            THEN  
    '10-20'
        
    WHEN AVGTIMESTAMPDIFFMINUTE A.access_start_datetimeA.access_end_datetime ) ) >21 <31
            THEN  
    '20-30'
        
    ELSE  '30+'
         
    END AS value
    FROM stats_access A
    JOIN users U ON U
    .id A.fb_id
    WHERE 
    (A.fb_id IS NOT NULL)
    GROUP BY A.domain_idfieldCASTA.access_start_datetime AS DATE 
    to get the avg time on site by age ranges ?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by whisher View Post
    Is it right this query
    what happened when you tested it? ™
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what happened when you tested it? ™
    It actually works quite well
    except I forgot
    PHP Code:
    avg(timestampdiff(MINUTE,`A`.`access_start_datetime`,`A`.`access_end_datetime`)) AS `subfield
    sorry to bother you for this but being not very good at querielogy ....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •