我有一个非常直接的查询,它选择了一对商业名称并计算其他两个连接表的结果。出于某种原因,我获得了与规则相同数量的优惠,即使该数字仅适用于规则。
例如,我有2个优惠和6个规则。返回的结果显示为6。
我错过了什么?
Return the number of seconds later that a time in seconds
time_2 is than a time in seconds time_1.
>>> seconds_difference(1800.0, 3600.0)
1800.0
>>> seconds_difference(1800.0, 3600.0)
-1800.0
>>> seconds_difference(1800.0, 2160.0)
360.0
>>> seconds_difference(1800.0, 1800.0)
0.0
"""
答案 0 :(得分:3)
使用DISTINCT
,这样您就不会多次计算相同的ID。
SELECT
business_profile.busID,
business_profile.busName,
COUNT(DISTINCT business_offers.ofr_id) AS cntOffers,
COUNT(DISTINCT business_rules.rule_id) AS cntRules