SELECT saleamount/(SELECT SUM(saleamount)
from user_pr where user_id=49) *100 as totalPercentage
from user_pr where user_id=49
我也想加入
select users.firstname from users where type=1
如何在一个查询中组合两者
答案 0 :(得分:-2)
取两个表名,将JOIN置于then和ON之间,并在第二个之后加入条件。
SELECT saleamount/(SELECT SUM(saleamount)
from user_pr where user_id=49) *100 as totalPercentage,
users.firstname
from user_pr JOIN users ON user_pr.user_id = users.user_id
where user_pr.user_id = 49
and users.type = 1