MySQL Query每次都显示不一致的结果

时间:2015-05-12 11:08:57

标签: mysql

SELECT DISTINCT pv.product_variation_key,
                p.product_key,
                p.brand_key,
                p.name,
                p.vehicle_type,
                p.short_description,
                pp.medium_image,
                b.brand_name,
                b.big_image,
                ts.tire_size,
                pv.sku,
                pv.price,
                pv.dealer_price,
                pv.retail_price,
                pv.weight,
                pv.width,
                pv.performance_rating,
                pv.mileage_warranty,
                pv.overall_diameter,
                pv.tread_depth,
                pv.maximum_psi,
                vte.road_hazard,
                vte.road_hazard_price,
                vte.load_index,
                vte.sidewall,
                vte.UTQG,
                vte.load_ply_rating,
                vte.load_range,
                tsr.tire_speed_rating,
                cr.rating,
                IF(pv.sku != i.sku,'true','false'),
                ROUND((((acos(sin((41.3309413*pi()/180)) * sin((sc.latitude*pi()/180)) + cos((41.3309413*pi()/180)) * cos((sc.latitude*pi()/180)) * cos((abs(-75.7429636 - sc.longitude)*pi()/180))))*180/pi())*60*1.1515) , 1) AS distance
FROM (products p,
      product_variations pv,
      brands b,
      tire_sizes ts,
      variation_tire_size_applications vts,
      variation_tire_extradatas vte,
      inventorys i,
      supply_chain_centers sc)
LEFT JOIN customer_reviews cr ON cr.product_key = p.product_key
AND cr.is_approved = 'yes'
LEFT JOIN variation_tire_speed_rating_applications vtsra ON vtsra.product_variation_key = pv.product_variation_key
LEFT JOIN tire_speed_ratings tsr ON vtsra.tire_speed_rating_key = tsr.tire_speed_rating_key
LEFT JOIN product_photos pp ON p.product_key = pp.product_key
AND pp.photo_type= 'default image'
WHERE pv.product_key = p.product_key
  AND p.status = 'active'
  AND b.brand_key = p.brand_key
  AND pv.product_variation_key = vts.product_variation_key
  AND ts.tire_size_key = vts.tire_size_key
  AND pv.product_variation_key = vte.product_variation_key
  AND i.supply_chain_center_key = sc.supply_chain_center_key
  AND i.brand_key = p.brand_key
  AND sc.status = 'Active'
  AND pv.sku=i.sku
  AND i.current_stock > 0
  AND (p.name LIKE '%win%'
       OR pv.variation_name LIKE '%win%'
       OR p.product_type LIKE '%win%'
       OR b.brand_name LIKE '%win%'
       OR LCASE(pv.sku) LIKE '%win%')
GROUP BY pv.product_variation_key
HAVING (distance <= 1000)
ORDER BY pv.retail_price ASC,
         cr.rating DESC,
         p.name ASC

我面临着MySQL查询的问题,每次在phpmyadmin中显示不一致的结果我认为这个问题是因为纬度和经度而发生的。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

使用GROUP BY时的简单规则:

  

SELECT子句中的每一列都必须在GROUP BY子句中,否则必须对其应用聚合函数!

如果不是这种情况,则会显示每组的随机行。据我所知,MySQL是唯一允许这样做的DBMS,但总是记住,这是错误的。您也可以通过设置ONLY_FULL_GROUP_BY SQL mode

来停用此功能