我有一个名为 tbl_populations 的表,其中包含以下字段:
pk_populationid,residence,value,aspect,gender,fk_tbl_states_stateid
我正在尝试计算两个方面的行差异
例如
SELECT fk_tbl_states_stateid, value - (
SELECT value
FROM tbl_populations
WHERE fk_tbl_states_stateid = '16'
AND fk_tbl_districts_districtid = '0'
AND residence = '0'
AND gender = '0'
AND aspect = '2' ) AS difference
FROM tbl_populations
WHERE fk_tbl_states_stateid = '16'
AND fk_tbl_districts_districtid = '0'
AND residence = '0'
AND gender = '0'
AND aspect = '1'
它工作正常,因为它返回一行
为了获取我想要检索所有性别值的多个数据,我已从条件中删除了性别。
SELECT fk_tbl_states_stateid,gender, value - (
SELECT value
FROM tbl_populations
WHERE fk_tbl_states_stateid = '16'
AND fk_tbl_districts_districtid = '0'
AND residence = '0'
AND aspect = '2' ) AS difference
FROM tbl_populations
WHERE fk_tbl_states_stateid = '16'
AND fk_tbl_districts_districtid = '0'
AND residence = '0'
AND aspect = '1'
我收到Subquery returns more than 1 row
错误。
我怎样才能得到所有的结果?