title: mysql view: count and for loop in the query
body: <p>I'm working with mysql.  Need to create a view where the query must include some      <code>MIN(case when then else end)</code> statements.<br>
  I don't know how many Case statements do I have to write,  because this value depends upon one of the tables related to the view, say table B.  So my view must have a dynamic number of cases inside the select statement.
  I want to know how can it be achieved.  I think it can be achieved by counting the number of rows in table B,  then setting this value as a variable (@q) and then using a while loop inside the select statement to dynamically create as many MIN(case when then else end) statements required.  Thanks for the help.</p>