计算查询中的一行在所有表中出现的次数


count how many times a row from a query appear on all the table

我有这个查询,它工作正常

  $con    = "SELECT     id, fecha, id_px FROM mytable WHERE date='$fe' AND id_nut='$id' AND id_suc = '$su' AND confirm != '3'

但我需要知道这个查询得到的每个id_px在表上出现了多少次,而不考虑日期和其他标准

类似于这个查询

 SELECT id_px, paciente, id FROM consultas2 WHERE id_px='$id_px' AND cobrado=1 LIMIT 22  

我需要的最终结果是第一次查询的所有数据,比如这个

$consultas = array(
    'id'     => $tim['id'],
    'id_nutr' => $tim['id_nut'],
    'date'    => $tim['date'],
        --this is the data i need--> 
    'total_cns' =>$tim['?']
        --the total of num rows of the second query--
);

如何做到这一点?提前感谢!

这将为您提供与$id_px 匹配的结果总数

SELECT count(*) FROM consultas2 WHERE id_px='$id_px' AND cobrado=1