ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

mysql query not working with query module

February 11, 2011 12:26pm

Subscribe [3]
  • #1 / Feb 11, 2011 12:26pm

    Interfacer

    92 posts

    Hi

    I have written this query and it is running juts fine in ee sql manager.
    It breaks when I embed it in ee template like so:

    {exp:query sql="
        SELECT 
            SUM(field_id_2+field_id_3+field_id_4+field_id_5+field_id_6+field_id_7)/(6*(
                SELECT 
                    COUNT(entry_id) 
                FROM 
                    exp_channel_titles 
                AS
                    average
                WHERE 
                    channel_id="1" 
                AND 
                    status="final"))
                FROM 
                    exp_channel_data 
                WHERE 
                    entry_id IN 
                    (SELECT entry_id         
                    FROM exp_channel_titles 
                    WHERE status="final");
        "}
        {average}
    {/exp:query}

    The query creates an average of field type values across entries. No error message.
    Thanks

    [Mod Edit: Moved to the CodeShare Corner]

  • #2 / Feb 11, 2011 12:36pm

    Billy Patel

    284 posts

    Try swapping double quotes for single quotes around 1, final etc, failing that put query all on one line.

  • #3 / Feb 11, 2011 12:46pm

    Interfacer

    92 posts

    Hi BohBoh

    that seemed to have help a bit since the page now at least renders the html.

    But still no value in the {average} variable, any ideas?

    Cheers

  • #4 / Feb 11, 2011 12:52pm

    Kevin Cupp

    791 posts

    Try putting “AS average” after your subquery that calculates the average. That way, it’ll assign the alias to the results of that subquery. Ex:

    ...AND status="final")) AS average FROM exp_channel_data…
  • #5 / Feb 11, 2011 12:56pm

    Interfacer

    92 posts

    Hi Kevin
    Thanks, that solved it!
    Cheers

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases