我有这样的mysql查询:
$statement=$pdo->prepare("SELECT id AS Activity_ID,type,status,description,
(SELECT SUM(price*worked_hours) FROM tbl_working_hours
WHERE id_act = Activity_ID) AS total_hours FROM tbl_activity");
有两个表:
1- tbl_activity
2- tbl_working_hours
我正在尝试根据另一个表的摘要为每一行创建虚拟列。
由于
答案 0 :(得分:0)
您可能想要使用子查询
SELECT [...], (SELECT COUNT(*) FROM mytable) AS count FROM myothertable
这是我心中唯一的解决方案。问题是,在性能方面,这种方式非常昂贵。