SELECT count(*) FROM sale_1110 where salerid ="01022";
SELECT count(*) FROM sale_1109 where salerid ="01022";
SELECT count(*) FROM sale_1108 where salerid ="01022";
SELECT count(*) FROM sale_1107 where salerid ="01022";
如将这几结果相加
select sum(col) from (
SELECT count(*) col FROM sale_1110 where salerid ="01022" union all
SELECT count(*) col FROM sale_1109 where salerid ="01022和select sum(col) from (
SELECT count(*) col FROM sale_1110 where salerid ="01021" union all
SELECT count(*) col FROM sale_1109 where salerid ="01021" union all
可以整编成,结果是二列
??
追问条件salerid 不一样,不想一个个查,可以一个语句查出来吗? 当只是salerid一样的求和
追答如果数据量大,建议使用索引.
select count(salerid ) from (
SELECT salerid FROM sale_1110 union all
SELECT salerid FROM sale_1109 union all
SELECT salerid FROM sale_1108 union all
SELECT salerid FROM sale_1107) where salerid ="01022"