0

here is the sql query that i've tried.

function getall() { 
   $connection = new Connection; 
   $connection->open(); 
   $query = "SELECT position.id,position.name_position,position.g_position,position.cs,position.totalbefore,
            COUNT(position2.staff_id) AS cnt_staff,
            totalbefore-cnt_staff AS totalafter
            FROM position
            INNER JOIN position2 ON position.id = position2.id_position2
            WHERE position.status_data= '1'
            GROUP BY position2.id_position2";
    $result = mysql_query($query);
    return $result; 
}

This code return syntax error. Idk where to put the Arithmetic operation (totalbefore-cnt_staff AS totalafter) in the statement.can anyone help me pls

1
  • Check you column name like this "totalbefore-cnt_staff". It may be totalbefore_cnt_staff Commented Feb 11, 2016 at 4:59

2 Answers 2

1

Use

position.totalbefore - COUNT(position2.staff_id) AS totalafter

You need to calculate the value again

Sign up to request clarification or add additional context in comments.

Comments

0

Since you have a group by clause in the query, you must use an aggregate function with your arithmetic expression such as

sum(totalbefore-cnt_staff) as totalafter

and the same for the totalbefore column.

anyways, try to put the query in any query editor such as (SQL query editor) and the error messages will be more clear for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.