我必须找到最新帐户(资本*)余额(他们可能有多个帐户)的客户数量,balance_value超过1.000.000
* capital:balance_type ='Capital'
我想我的查询会返回错误的结果并且效率低下
SELECT COUNT(DISTINCT customer.customer_id) AS customers
FROM balance INNER JOIN account ON balance.account_id = account.account_id
INNER JOIN contract ON account.contract_id = contract.contract_id
INNER JOIN customer ON customer.customer_id = contract.customer_id
WHERE balance.balance_type like '%Capital%' AND balance.balance_value > 1000000
ORDER BY balance.balance_date DESC
我想我需要一些帮助:S
下载示例数据(将Data文件夹移动到C:/)和脚本以创建架构 https://drive.google.com/file/d/0BxVNamixm4W2SHVadndtWkNBajg/view?usp=sharing
答案 0 :(得分:0)
您的查询结果是什么?
你期望什么样的'正确'结果?
仅供参考,
按customer_id分组会比分开
更快如果你知道确切的大写字,最好使用EQUAL TO / =而不是LIKE(=比LIKE快)