日期:2014-05-16  浏览次数:20871 次

奇葩的sql语句,搞死我了,求救~~~~
SQL code

SELECT DISTINCT p.products_image, pd.products_name, p.products_quantity, 
p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, 
p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status 
= 1, s.specials_new_products_price, NULL) as specials_new_products_price, 
IF(s.status =1, s.specials_new_products_price, p.products_price) as final_price, 
p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, 
p.products_qty_box_status FROM products p LEFT JOIN specials s on p.products_id 
= s.products_id LEFT JOIN products_description pd on p.products_id = 
pd.products_id JOIN products_to_categories p2c on p.products_id = 
p2c.products_id JOIN products_attributes p2a on p.products_id = p2a.products_id 
JOIN products_options po on p2a.options_id = po.products_options_id JOIN 
products_options_values pov on p2a.options_values_id = 
pov.products_options_values_id WHERE p.products_status = 1 and pd.language_id = 
'1' and p2c.categories_id = '23' GROUP BY p.products_id HAVING ( 
FIND_IN_SET("GiftOptionsCollector\'s Tin", 
GROUP_CONCAT(CONCAT(REPLACE(po.products_options_name, " ", ""), 
pov.products_options_values_name)))) order by p.products_sort_order, 
pd.products_name limit 10


返回空值
我删除了order by p.products_sort_order, pd.products_name 有返回值
这是什么情况~

然后我复制了这条语句FIND_IN_SET的GiftOptionsCollector\'s Tin 值 把他替换成ColorOrange
神奇的事情发生了 有返回值了 ,语句如下,瞬间石化~
SQL code
SELECT DISTINCT p.products_image, pd.products_name, p.products_quantity, 
p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, 
p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status 
= 1, s.specials_new_products_price, NULL) as specials_new_products_price, 
IF(s.status =1, s.specials_new_products_price, p.products_price) as final_price, 
p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, 
p.products_qty_box_status FROM products p LEFT JOIN specials s on p.products_id 
= s.products_id LEFT JOIN products_description pd on p.products_id = 
pd.products_id JOIN products_to_categories p2c on p.products_id = 
p2c.products_id JOIN products_attributes p2a on p.products_id = p2a.products_id 
JOIN products_options po on p2a.options_id = po.products_options_id JOIN 
products_options_values pov on p2a.options_values_id = 
pov.products_options_values_id WHERE p.products_status = 1 and pd.language_id = 
'1' and p2c.categories_id = '23' GROUP BY p.products_id HAVING ( 
FIND_IN_SET("ColorOrange", GROUP_CONCAT(CONCAT(REPLACE(po.products_options_name, 
" ", ""), pov.products_options_values_name)))) order by p.products_sort_order, 
pd.products_name limit 10




下面是几个表的数据 数据有点大
http://l9.yunpan.cn/lk/83qno1fuvy

------解决方案--------------------
测试下,情况确实和楼主一样。但是报了一个warning,提示group_concat 被截断,故:
set global group_concat_max_len= 999999999;

重新连接执行。就有结果了。
------解决方案--------------------
测试确实是如此,
执行你的SQL语句,

SHOW WARNINGS,提示截断 group_concat,设置group_concat_max_len即可

使用group_concat_max_len系统变量,你可以设置允许的最大长度。
 程序中进行这项操作的语法如下,其中 val 是一个无符号整数:
 SET [SESSION | GLOBAL] group_concat_max_len = 10000000;
------解决方案--------------------
探讨

测试下,情况确实和楼主一样。但是报了一个warning,提示group_concat 被截断,故:
set global group_concat_max_len= 999999999;

重新连接执行。就有结果了。