<code>
select t.range as [Type], count(*) as [Value]
from (select case
when answer_count between 0 and 5 then 'PCS'
when answer_count between 5 and 10 then 'PRINTER'
else 'KEYBOARD' end as range
from points where type='product_quiz') t
group by t.range
</code>
Output is: --------------------- Type | Value --------------------- PCS 129195 PRINTER 121327 OTHERS 236548 I want to echo only for the printer value using PHP. For example I want the result like this: echo $printer = '121327';
答案 0 :(得分:0)
试试这个:
$query = mysql_query("select t.range as [Type], count(*) as [Value]
from (select case
when answer_count between 0 and 5 then 'PCS'
when answer_count between 5 and 10 then 'PRINTER'
else 'KEYBOARD' end as range
from points where type='product_quiz') t
group by t.range");
while($row = mysql_fetch_assoc($query))
{
if($row['type'] == 'PRINTER'){
echo $printer = $row['value'];
}
}