请高手前来指点mysql语句整合问题!!!急,在线!!!
第一句
select user_name,sum(company_part)as company_part from
bets_casino where(home_team_name=1) group by user_name order by company_part desc limit 1
第二句
select
count(*),
sum(company_part),
sum(user_amount),
sum(company_amount),
sum(IF(goal_home=3,odds*(1-sole_per-parter_per),amount*(1-sole_per-parter_per))),
sum(IF(goal_home=3,odds*(1-sole_per-parter_per)*0.008,amount*(1-sole_per-parter_per)*0.008))
from bets_casino where(home_team_name=1)
MYSQL中怎样才能将2句查询语句合并为一条呢?在查询第2句的时候,也能得出第一句的结果??????
------解决方案--------------------
把两个表用 inner join连起来试试。
SQL code
select * from (select user_name,sum(company_part)as company_part from bets_casino where(home_team_name=1) group by user_name order by company_part desc limit 1)as a
inner join
(select count(*), sum(company_part), sum(user_amount), sum(company_amount), sum(IF(goal_home=3,odds*(1-sole_per-parter_per),amount*(1-sole_per-parter_per))), sum(IF(goal_home=3,odds*(1-sole_per-parter_per)*0.008,amount*(1-sole_per-parter_per)*0.008)) from bets_casino where(home_team_name=1)) as b;