आपको सभी मूल्य श्रेणियों वाली एक इनलाइन तालिका बनानी होगी। फिर एक LEFT JOIN
अपेक्षित परिणाम प्राप्त करने के लिए आपकी क्वेरी के आधार पर एक व्युत्पन्न तालिका के साथ:
SELECT x.PriceRange, COALESCE(TotalWithinRange, 0) AS TotalWithinRange
FROM (
SELECT "0 - 10" AS PriceRange
UNION SELECT "10 - 20"
UNION SELECT "20 - 30"
UNION SELECT "30 - 40"
UNION SELECT "40 - 50"
UNION SELECT "over 50" ) x
LEFT JOIN (
SELECT
CASE when price >= 0 and price <= 10 then "0 - 10"
when price > 10 and price <= 20 then "10 - 20"
when price > 20 and price <= 30 then "20 - 30"
when price > 30 and price <= 40 then "30 - 40"
when price > 40 and price <= 50 then "40 - 50"
else "over 50"
END AS PriceRange,
COUNT(*) as TotalWithinRange
FROM YourTable
GROUP BY 1 ) y ON x.PriceRange = y.PriceRange