上帝的一天。
我使用 MsSQl Server 2008;
代码:
$entersql="SELECT name
FROM (
SELECT name FROM
Hist_answer
WHERE id_city='$id_city' AND id_firm='$id_firm' AND id_service='$id_service'
) x
GROUP BY name
";
$enterres = sqlsrv_query($conn, $entersql, $params, $options);
while($i = sqlsrv_fetch_array($enterres, SQLSRV_FETCH_ASSOC))
{
if($inputby=='id_hist_answer'&&$typeby=='DESC'){$a--;}else{$a++;}
$name=($i['name']!='')? $i['name']:'0';
$sql11="SELECT
ha.unit as ha_unit,
ha.id_producer_goods as ha_id_producer_goods
FROM Hist_answer ha
WHERE ha.id_city='$id_city' AND ha.id_firm='$id_firm' AND ha.id_service='$id_service' AND ha.name='$name'";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$res11 = sqlsrv_query($conn, $sql11,$params,$options);
$row_count_ha = sqlsrv_num_rows($res11);
}
在这段代码中,我这样做:
1)我选择了所有唯一的name
(group by name
);
2) 在第二个 sql($sql11) 中,我确实找到了每个name
.
请告诉我,当我可以找到所有唯一的name
( group by name
) 并计算每个唯一的行时, sql 如何做name
?