users(id, account_balance)grocery(user_id, date, amount_paid)fishmarket(user_id, date, amount_paid)
fishmarket
grocery
SELECT t1."id" AS "User ID", t1.account_balance AS "Account Balance", count(t2.user_id) AS "# of grocery visits", count(t3.user_id) AS "# of fishmarket visits"FROM users t1LEFT OUTER JOIN grocery t2 ON (t2.user_id=t1."id") LEFT OUTER JOIN fishmarket t3 ON (t3.user_id=t1."id") GROUP BY t1.account_balance,t1.idORDER BY t1.id
"1", "12", "12"
.LEFT JOIN
grocery
fishmarket
"1", "3", "4"
.
海绵宝宝撒
相关分类