鉴于下表:
type | valueOfType
food | 4.3
food | 5.3
dairy | 3.2
food | 1.3
food | 6.7
==============
我的查询需要搜索所有“food”类型并添加所有“valueOfType”,其中valueOfType是float类型。我该怎么做?
编辑:
$query = "SELECT SUM(valueOfType) AS Total FROM productTbl WHERE type ='$post_type' ";
$result = mysql_query($query2)
or die("Unable to execute query because : " . mysql_error());
echo $result;
答案 0 :(得分:5)
SELECT SUM(valueOfType) AS Total FROM foo WHERE type='food'