Skip to content

Instantly share code, notes, and snippets.

@justenj
Last active July 5, 2016 18:15
Show Gist options
  • Save justenj/fa3db80e9fad8f1c94cd to your computer and use it in GitHub Desktop.
Save justenj/fa3db80e9fad8f1c94cd to your computer and use it in GitHub Desktop.
ALTER
ALGORITHM = UNDEFINED
DEFINER=`k_test`@`localhost`
SQL SECURITY DEFINER
VIEW `Import`
AS select
`s_products`.`id` AS `id`,
`s_products`.`url` AS `url`,
`s_brands`.`name` AS `brand`,
`s_products`.`name` AS `name`,
`s_products`.`annotation` AS `annotation`,
`s_products`.`body` AS `body`,
`s_products`.`visible` AS `visible`,
`s_products`.`position` AS `position`,
`s_products`.`meta_title` AS `meta_title`,
`s_products`.`meta_keywords` AS `meta_keywords`,
`s_products`.`meta_description` AS `meta_description`,
`s_products`.`created` AS `created`,
`s_products`.`featured` AS `featured`,
`s_products`.`external_id` AS `external_id`,
`s_products`.`hit` AS `hit`,
`s_variants`.`price` AS `price`,
`s_variants`.`compare_price` AS `compare_price`,
group_concat(distinct `s_images`.`filename` order by `s_images`.`position` ASC separator ',') AS `images`,
group_concat(distinct `s_products_categories`.`category_id` order by `s_products_categories`.`position` ASC separator ',') AS `categories`,
group_concat(distinct `s_products_videos`.`link` order by `s_products_videos`.`position` ASC separator ',') AS `videos`,
group_concat(distinct `s_related_products`.`related_id` order by `s_related_products`.`position` ASC separator ',') AS `related`,
group_concat(distinct `s_features`.`name`,'==',`s_options`.`value` order by `s_options`.`feature_id` ASC separator ',') AS `options`
from `s_products`
left join `s_brands` on `s_products`.`brand_id` = `s_brands`.`id`
left join `s_images` on `s_images`.`product_id` = `s_products`.`id`
left join `s_products_categories` on `s_products_categories`.`product_id` = `s_products`.`id`
left join `s_products_videos` on `s_products_videos`.`product_id` = `s_products`.`id`
left join `s_related_products` on `s_related_products`.`product_id` = `s_products`.`id`
left join `s_variants` on `s_variants`.`product_id` = `s_products`.`id`
left join `s_options` on `s_options`.`product_id` = `s_products`.`id`
left join `s_features` on `s_features`.`id` = `s_options`.`feature_id`
group by `s_products`.`id`
select
`set_items`.`id`,
`set_items`.`parent_id`,
`set_items`.`objective`,
`set_items`.`origin`,
`phrases`.`id` as `phrase_id`,
`phrases`.`text`,
`frequencies`.`base`,
`frequencies`.`kei`,
`positions`.`position`,
`pages`.`url`,
`page_planes`.`url` as `url_planes`
from `set_items`
inner join `queries` on `set_items`.`query_id` = `queries`.`id`
inner join `phrases` on `queries`.`phrase_id` = `phrases`.`id`
inner join `positions` on `positions`.`query_id` = `queries`.`id`
left join `pages` on `positions`.`page_id` = `pages`.`id`
left join `pages` as `page_planes` on `queries`.`page_id` = `page_planes`.`id`
inner join `frequencies` on
`frequencies`.`phrase_id` = `queries`.`phrase_id`
and
`frequencies`.`region_id` = `queries`.`region_id`
left join `frequencies` as `one_frequencies` on
`frequencies`.`phrase_id` = `one_frequencies`.`phrase_id`
and
`frequencies`.`date` < `one_frequencies`.`date`
where
`one_frequencies`.`date` is null
and
`set_items`.`set_id` = 1
group by `set_items`.`id`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment