Advertisement
scramble_boy

Untitled

Mar 4th, 2020
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.49 KB | None | 0 0
  1. select a.sku, a.name, group_concat(attributes.name SEPARATOR '\t'),
  2. group_concat((case when attributes.value_type = 'multiple_select' then
  3.                                         COALESCE((select  group_concat(
  4.                                             concat(o.value,COALESCE(concat(" ",(select code from product_units where id = o.unit_id)),""))
  5.                                     ) from product_attribute pa
  6.                                         JOIN tblIndex
  7.                                         join attribute_options o on o.id = (SUBSTRING_INDEX(SUBSTRING_INDEX(pa.value, ',', ntIndex), ',', -1))
  8.                                                     and ntIndex <= 1 + LENGTH(pa.value) - LENGTH(REPLACE(pa.value,',','')) 
  9.                                         where pa.product_id = a.id and pa.attribute_id = attributes.id             
  10.                                         ),"")
  11.                                 ELSE
  12.                                 COALESCE((select (case when attributes.value_type = "text" then
  13.                                                                                     concat(pa.value,COALESCE(concat(" ",(select code from product_units where id = pa.unit_id)),""))
  14.                                                                         else
  15.                                                                                     concat(o.value,COALESCE(concat(" ",(select code from product_units where id = o.unit_id)),""))
  16.                                                                         end) from product_attribute pa
  17.                                         left join attribute_options o on pa.value = o.id    
  18.                                         where pa.product_id = a.id and pa.attribute_id = attributes.id
  19.                                 ),"") end) SEPARATOR '\t')
  20. from products a join attribute_groups e on a.attribute_set_id = e.attribute_set_id
  21. join attribute_group_attribute d on d.attribute_group_id = e.id
  22. join attributes on  d.attribute_id = attributes.id
  23. where a.attribute_set_id = 15 and a.seller_id = 1
  24. and a.created_at > '2020-02-05'
  25. group by a.sku
  26. limit 1000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement