title: SQL logic and/or PHP application w/ multiplication & addition (am I taking the right approach or all wrong?)
body: <p>I'm working out some psuedo code for an application problem. I would like some advice on if <strong>Am I even remotely on the right track here or am I going about this all wrong?</strong></p>
  
  <p><strong>I have 3 entry values for query:</strong></p>
  
  <p><em>Applicant Age<br>
  Spouse Age<br>
  Number of Children</em> </p>
  
  <p>I have one rate in my rates table for each of the above values. For example, for Applicant Age > 65, I have rate $50.00. And Spouse Age >= 18 or &lt;= 64, I have rate $40.00. Children have their own rate the same way, but there can be multiple children.</p>
  
  <p><strong>Here is the breakdown of my problem:</strong></p>
  
  <ol>
  <li><p>There is one record per applicant type (applicant, spouse and children). Each type has its own rate. </p></li>
  <li><p>I need to return a <strong>total rate</strong> result within the confines of SQL (this is what I am hoping for), so I can build this into my existing query. So essentially I am trying to create a "magically appearing" record based on some math within the SQL. In other words, there is no record in my rates table that would contain this result amount, it would be calculated within the confines of SQL.</p></li>
  </ol>
  
  <p><strong>Real example:</strong> appliant_age = 24 (rate $50.00), spouse_age = 20(rate $40.00), number_of_children = 3(rate $20 x 3(number entered) rate $60.00). Total rate = $150.00.</p>
  
  <p>A "magic result" record should be created which would just be built into my standard SQL results (which is already existing and working). And based on my example, it would be $150.00. And I should also be able to pass this value to my script from the query. </p>
  
  <p>My main rates table (w/ applicable fields) is set up like:</p>
  
  <pre><code>CREATE TABLE `rates` (
    `id` int(11) NOT NULL auto_increment,
    ...
    `monthly_cost` decimal(18,2) NOT NULL,
    `age_id` int(11) NOT NULL, // e.g. 0-17 (child), 18-65 (adult), 65+ (elder) etc...
    PRIMARY KEY  (`id`)
  )
  </code></pre>
  
  <p>NO I AM NOT LOOKING FOR ANYONE TO WRITE CODE FOR ME. JUST NEED SOME GUIDANCE ON WHICH IS THE BEST LOGICAL APPROACH TO THIS PROBLEM.</p>