我有一个products表,其中包含列id、price、category和city。我需要找到Barcelona城市里最便宜的veggies的数量。
我尝试了这个SQL查询,但得到了一个错误:
SELECT COUNT( * )
FROM products
HAVING lower(category) = 'veggies' AND lower(city) = 'Barcelona'
AND price = (SELECT MIN(price)
FROM products
WHERE l
我有一个表social_accounts,其中的facebook_id列有一个部分索引,其中user_id IS NULL。
如果我执行一个简单的查询WHERE facebook_id = '123',则使用索引:
=> EXPLAIN for: SELECT "social_accounts".* FROM "social_accounts" WHERE (user_id IS NOT NULL) AND "social_accounts"."facebook_id" = '123'