Skip to content

Instantly share code, notes, and snippets.

@alivesay
Last active December 20, 2015 18:48
Show Gist options
  • Save alivesay/6178310 to your computer and use it in GitHub Desktop.
Save alivesay/6178310 to your computer and use it in GitHub Desktop.
SELECT
count(*)
FROM
public.location_group
WHERE
port_number = $1
AND (
(
is_valid
AND id IN (
SELECT
location_group_id
FROM
public.location_group_location
WHERE
location_id IN (
SELECT
id
FROM
public.location
WHERE
code IN (
SELECT
location
FROM
record.item_record
WHERE
record_id IN (
$2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
)
)
)
)
OR (
is_valid = false
AND id NOT IN (
SELECT
location_group_id
FROM
public.location_group_location
WHERE
location_id IN (
SELECT
id
FROM
public.location
WHERE
code IN (
SELECT
location
FROM
record.item_record
WHERE
record_id IN (
$12, $13, $14, $15, $16, $17, $18, $19, $20, $21
)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment