我有一个查询:SELECT users.name, COUNT(DISTINCT leads.id) as leads,COUNT(DISTINCT properties.id) as properties,COUNT(DISTINCT buyers.id) as buyers,nullFROM usersLEFT JOIN (SELECT * from leads WHERE date(created_at) BETWEEN '2019-04-13' AND'2019-04-13') leads ON users.id = leads.user_idLEFT JOIN (SELECT * from properties WHERE date(contract_start_date) BETWEEN '2019-04-13' AND'2019-04-13') as properties ON users.id = properties.user_idLEFT JOIN (SELECT * from buyers WHERE date(created_at) BETWEEN '2019-04-13' AND'2019-04-13') as buyers ON users.id = buyers.user_idLEFT JOIN buyer_searches ON buyers.id = buyer_searches.buyer_idGROUP BY users.idUNIONSELECT users.name,null, null, null,COUNT(DISTINCT buyer_searches.id) as buyer_searchesFROM usersLEFT JOIN buyers ON users.id = buyers.user_idLEFT JOIN (SELECT * from buyer_searches WHERE date(created_at) BETWEEN '2019-04-08' AND'2019-04-13') as buyer_searches ON buyers.id = buyer_searches.buyer_idGROUP BY users.id我得到的表格中当然有重复的用户,但参数正确:users field1 field2 field3 etc....user1 data . null . null etc...user2 data . null . null etc...user1 null . data . data etc...user2 null . data .data etc...etc...我想按用户连接行。
1 回答
- 1 回答
- 0 关注
- 140 浏览
添加回答
举报
0/150
提交
取消