提前感谢您的帮助!
我需要根据2个不同的SELECT
加入2个表首先选择:
SELECT
Agent,
count( Online_playerdatabase_v2.First_Deposit_Date) as NumbFirstDeposits
FROM Online_playerdatabase_v2
WHERE Agent <>'Agent' AND Online_playerdatabase_v2.First_Deposit_Date BETWEEN '2015-12-01' AND '2015-12-31'
group by Agent
Output:
Agent NumbFirstDeposits
john 49
No Agent 1
mike 9
然后另一个选择:
SELECT
Agent,
COUNT(DISTINCT Online_customer_activity_v2.Customers) as ActivePlayers,
Truncate(sum(Online_customer_activity_v2.Real_Money),0) as RM,
Truncate(sum(Online_customer_activity_v2._Bonuses),0) as BO,
Truncate(sum(Online_customer_activity_v2.Total_Win_Loss),0) as GGR,
Truncate(sum(`Online_customer_activity_v2`.`Total_Bets`),0) as BETS
FROM Online_customer_activity_v2
WHERE `Online_customer_activity_v2`.`Date` BETWEEN '2015-12-01' AND '2015-12-31'
AND Online_customer_activity_v2.Total_Bets>0
GROUP BY Agent
Output:
Agent ActivePlayers RM BO GGR BETS
john 73 63118 28538 64 1395799
No Agent 1 80 0 - 21 876
mike 24 209780 28464 20 7955633
我希望如下所示加入2个输出:
Agent ActivePlayers RM BO GGR BETS NumbFirstDeposits
john 73 63118 28538 64 1395799 49
No Agent 1 80 0 - 21 876 1
mike 24 209780 28464 20 7955633 9
答案 0 :(得分:2)
在不必重写查询的情况下执行此操作的一种方法是在派生表中使用它们,如下所示:
select t1.*, t2.NumbFirstDeposits
from (<<your first query here>>) t1
join (<<your second query here>> t2 on t1.agent = t2.agent
答案 1 :(得分:1)
尝试以这种方式应用联接:
SELECT ***your_column_names_here***
FROM Online_playerdatabase_v2 as P
join Online_customer_activity_v2 as C on P.Agent=C.agent
WHERE
***conditions***
Group BY p.Agent
答案 2 :(得分:0)
你可以试试这个,
SELECT Online_customer_activity_v2.Agent,
COUNT(DISTINCT Online_customer_activity_v2.Customers) as ActivePlayers,
Truncate(sum(Online_customer_activity_v2.Real_Money),0) as RM,
Truncate(sum(Online_customer_activity_v2._Bonuses),0) as BO,
Truncate(sum(Online_customer_activity_v2.Total_Win_Loss),0) as GGR,
Truncate(sum(`Online_customer_activity_v2`.`Total_Bets`),0) as BETS,
count( Online_playerdatabase_v2.First_Deposit_Date) as NumbFirstDeposits FROM Online_customer_activity_v2 join Online_playerdatabase_v2 on Online_playerdatabase_v2.agent=Online_customer_activity_v2.agent WHERE `Online_customer_activity_v2`.`Date` BETWEEN '2015-12-01' AND '2015-12-31' AND Online_customer_activity_v2.Total_Bets>0 GROUP BY Online_customer_activity_v2.Agent