我已经创建了一个小猫数据库,我需要使用以下公式。在这方面,我有两张table:出生和处置。
Birth table contains id, dob, owner, date of purchase
disposal table contains id, date of disposal (dodisposal), cause of death, sold, treatment
我现在尝试使用下面的mysql查询为two表使用一个公式,但它不起作用。
Select birth.owner, (((select count(disposal.id) from disposal WHERE
dodisposal BETWEEN DATE_SUB(NOW(), INTERVAL 600 DAY) AND NOW()) /
(select count(birth.id) from birth where birth.id not in
(select disposal.id from disposal)
)
) * 100)
from birth left join disposal on
disposal.brandnumber = birth.id group by birth.owner
但我对所有车主的评价都是一样的:
ie公司
rita : 79.6
sunita : 79.6
Smith : 79.6
我预期的结果应该是通过以下公式得出的:
Number of deaths in the current year / total number of live cats * 100
1条答案
按热度按时间m4pnthwp1#
我找到了解决这个问题的方法,通过创建两个独立的视图,然后使用mysql查询它们的结果。