title: MySQL function with query inside it
body: <p>I used this mysql function to retrieve the sum of a column's data with passing three parameters. Function return the sum of whole column regardless of where clause. 
  I mean that the query inside the function act as it has no where clause and this query works fine when used without function.
  Here is the function</p>
  
  <pre><code>DELIMITER $$
  CREATE FUNCTION calculate_customer_loan(customer_id INT, currency VARCHAR(10), type VARCHAR(10)) RETURNS DOUBLE
  BEGIN
      DECLARE total DOUBLE;
      SELECT SUM(`amount`) INTO total FROM `deals` WHERE `customer_id` = customer_id AND `currency` = currency AND `type` = type;
      RETURN total;
  END
  $$
  DELIMITER ;
  </code></pre>
  
  <p>Any idea!
  help me.</p>