Advanced SQL Question

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Advanced SQL Question

    I'm working on a side project and need to use a SQL query to return aggregate
    numbers for for date/time ranges, i.e. if I wanted to return the number of
    times a particular CF template was hit during the course of 24 hours, by hour:

    Assuming 1 24-hour period and the resource is index.cfm, I want to see:
    12AM - 1AM, 200 hits
    1AM-2AM, 23 hits
    2AM-3AM, 99 hits

    So for a 24-hour period, I need 24 rows returned by my query. I could do this
    with a stored procedure or by issuing 24 separate queries, but I suspect it can
    be done with one query. I just can't quite figure out how to structure the
    query so I get the results I want.

    Anyone have a suggestion?

    Laterz!

    cf.Objective Guest

  2. Similar Questions and Discussions

    1. advanced question: making <asp:ButtonColumn> CausesValidation=False
      Hi, i stated that this is an advanced question because i have a post from few days ago that i received answers to with suggestions that looked...
    2. Advanced Flash and layering question
      I'm trying to get HTML layered menus to appear over the top of a Flash movie. Okay, so we know that if set the wmode of the flash movie to...
    3. Advanced routing question
      Hi I'm trying to combine 2 linux firewalls/routers together. the final host should have the following ports: 1. eth0 - 256kbps frame relay....
    4. advanced SQL
      Until recently, I thought MySQL, and SQL in general was no problem....doing simple INSERTS, DELETES, and UPDATES;...then I heard about triggers,...
    5. Advanced Caching Question
      Hi, I guess you want to use the application cache and since the application can’t be share between servers (as session) you post your question....
  3. #2

    Default Re: Advanced SQL Question

    What database? what's your table look like?

    At a very high level, this is what you need to do:

    select count(*), hour from access_table where
    resource = 'index.cfm'
    and day = '6/1/2005'
    group by hour

    It's more complex than that because I'm assuming hour is embedded in a time
    field, which you'll have to do some processing on in order to group by a single
    hour.

    Kronin555 Guest

  4. #3

    Default Re: Advanced SQL Question

    If you don't want stored procedure but store each hit with time in database you
    could create reference table with 24 hours range records with 3 columns:
    hour_id, from, to; then count number of hits group by hour_id using join this
    table with the other one where hits related time.

    CF_Oracle Guest

  5. #4

    Default Re: Advanced SQL Question

    Hey Kronin,

    Thanks... that's the basic structure I've been looking for. For some reason,
    aggregate functions have always presented me with a challenege. That should get
    me pointed in the right direction.

    As far as your questions:
    Database is SQLServer 2000 on Wink2k AS
    Table structure is yet to be determined, but will probably look a lot like the
    W3C standard log format with the addition of a site key column provided by the
    system to the user, allowing me to create a log that supports any number of
    sites and extract stats for any of them by joining the user, site, and log
    tables.

    Thanks, I appreciate it.

    Laterz!

    cf.Objective Guest

  6. #5

    Default Re: Advanced SQL Question

    The solution that I am about to describe is similar to the one that you are
    about to employ, but doesn't require the use/creation of a table. Simply use
    the case statement in MSSQL in the select clause and the group by clause. That
    ought to solve your issue. Hope that this helps. Thanks.

    Chris

    cgsj_usa@yahoo.com Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139