Coding/SQL question…

Ok, folks….This one is going out to all of you who work in SQL, cold fusion, etc…

I am currently working on series of reports based on keyword search data that we have archived from our main web site.  The page I’m working on is supposed to display the most popular keywords in descending order.  My initial thought was that I’d be able to get the data with one SQL query like so…

SELECT Count(search_log.keyword) AS hitCount, search_log.keyword
FROM search_log
WHERE search_log.keyword IN (SELECT DISTINCT search_log.keyword FROM search_log)

The problem is that once I throw COUNT in the mix SQL doesn’t seem to like returning any additional data from the table, so I had to break it down and find the results with cold fusion.  Doing so requires me to run a huge series of queries to get all of my data and the page takes forever to load.  Here’s what I’m doing…

<cfquery name=”getLog” datasource=”#request.datasource#”>
    SELECT DISTINCT (search_log.keywords)
    FROM search_log
</cfquery>

<cfset keywordCountArray = ArrayNew(1)>

<cfloop query=”getLog”>
    <cfquery name=”getCount” datasource=”#request.datasource#”>
        SELECT COUNT(search_log.keywords) AS hitCount
        FROM search_log
        WHERE search_log.keywords = ‘#getLog.keywords#’
    </cfquery>
    <cfset keywordCountArray[getLog.currentRow] = getCount.hitCount>
</cfloop>

<cfset newColumn = queryAddColumn(getLog, ‘hitCount’, ‘Integer’, keywordCountArray)>

<cfquery name=”getLogData” dbtype=”query”>
    SELECT getLog.keywords, getLog.hitCount
    FROM getLog
    ORDER BY getLog.hitCount DESC
</cfquery>

My thoughts on how to improve this…

I could just cache the “getLogData” query and not run the rest of them if the query exists, but I’m not sure if I can check for the existence of a cached query in ColdFusion.

Do the logic in a stored procedure.  Would speed things up slightly but, I think, still require me to run a multitude of queries.

Re-write the SQL in some terribly simplistic way that I’m just not seeing because I’m being blind.

Any help out there, gang?

A word to the wise…

Changing a tire is much easier when you realize you have a tire jack in the other one.

Socket wrenches? Not so much.

Oh, my poor hands.

Dungeons and Dragons 4th Edition

Wow.

It’s…really different.

I can very much see why so many people are saying that it emulates a video game now.  It really does.  So far, though?  I gotta say I’m digging the changes a lot – especially for casters.  Gone are the days of only being able to cast 3 spells per day at first level.  Now you have “at will,” “per encounter,” and “daily” spells.

Yeah.

As far as the whole “you need miniatures” thing?  Yeah, you kinda do.  I already have a battle map and a box of plastic minis, and if I run out of those I have a whole jar full of change.  Problem solved.

I’m digging it, and I am very excited to take it out for a stroll with my gaming group.

Taking a break to snark…

Still in Denver and generally having a fantastic time of it.  I just had to take a brief moment to throw a bit of snark into my LJ, though. 

I just read the following in the Dragon*Con Live Journal community…

It is bad enough that BSG fans had to wait a year between seasons three and four. But to have some fracking suit have us wait ANOTHER year for the ‘mid season break’.

Possible resuming of BSG after the tenth epp in mid July. Is Late 08 to mid 09.

I am so glad i download the show. No one gets paid a dime for my watching the show. Here i had felt kind of bad because no one was getting any advertising revenue from me watching commercials. So i had planned on picking up the DVD’s. Since i enjoyed the show so much. If i purchase the DVD’s now. I make sure to pick them up from a seller in Hong Kong.

I do not care who’s fault it is. Weather it is Ron or some suit at the Sci-Fi channel. You do not treat fans like this.

Ok…seriously?  You can’t see the irony in your post?  You talk about how they fuck over the “fans” in the same post where you state that you always download them (confirming in a comment that it’s through BitTorrent) and haven’t purchased the DVD’s.  If you “enjoyed the show so much” maybe, just maybe, you could have…I dunno…done something to make sure that the network made some money off of you so that they’d have some motivation to keep it on the air??

This right here, my friends?  This is why we have shit like Survivor and American Idol.  You want quality television?  Watch it.  You know, when it’s actually on the air?  If you miss it when it’s on the air watch it on the network website if they offer the option.  BitTorrent is all fine and dandy, but if you’re making sure that the networks aren’t getting any of your advertising dollars you have no right to bitch if they cancel the show you’re downloading. 

I’d have thrown my 2 cents in there, but the post already has 51 comments of “yeah, fuck them” and there are just some battles not worth fighting.