Skip to content

Instantly share code, notes, and snippets.

@herpaderpaldent
Created November 4, 2021 15:34
Show Gist options
  • Save herpaderpaldent/a4dceaf3f875df3cbe93df9c7377375d to your computer and use it in GitHub Desktop.
Save herpaderpaldent/a4dceaf3f875df3cbe93df9c7377375d to your computer and use it in GitHub Desktop.
select `location_id`
from `assets`
where `assetable_id` in (95725047, 96205695)
and `location_flag` in ('Hangar', 'AssetSafety', 'Deliveries')
and `item_id` in (select `item_id`
from ((select `item_id` from `assets` where `name_normalized` like 'ammo%')
union
(select `assets`.`item_id`
from `assets`
left join `universe_types` on `universe_types`.`type_id` = `assets`.`type_id`
left join `universe_groups`
on `universe_groups`.`group_id` = `universe_types`.`group_id`
where `universe_types`.`name_normalized` like 'ammo%'
or `universe_groups`.`name_normalized` like 'ammo%')
union
(select `assets`.`item_id`
from `assets`
inner join `assets` as `content` on `content`.`location_id` = `assets`.`item_id`
left join `universe_types` on `universe_types`.`type_id` = `content`.`type_id`
left join `universe_groups`
on `universe_groups`.`group_id` = `universe_types`.`group_id`
where `content`.`name_normalized` like 'ammo%'
or `universe_types`.`name_normalized` like 'ammo%'
or `universe_groups`.`name_normalized` like 'ammo%')
union
(select `assets`.`item_id`
from `assets`
inner join `assets` as `content` on `content`.`location_id` = `assets`.`item_id`
inner join `assets` as `content_content`
on `content_content`.`location_id` = `content`.`item_id`
left join `universe_types`
on `universe_types`.`type_id` = `content_content`.`type_id`
left join `universe_groups`
on `universe_groups`.`group_id` = `universe_types`.`group_id`
where `content_content`.`name_normalized` like 'ammo%'
or `universe_types`.`name_normalized` like 'ammo%'
or `universe_groups`.`name_normalized` like 'ammo%')) as `matches`)
group by `location_id`
order by `location_id` asc
limit 3 offset 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment