Skip to content

Instantly share code, notes, and snippets.

@workze
Last active February 12, 2020 14:07
Show Gist options
  • Save workze/c72befcef129aaba94bcfb4be71771a5 to your computer and use it in GitHub Desktop.
Save workze/c72befcef129aaba94bcfb4be71771a5 to your computer and use it in GitHub Desktop.
all about sql
WITH finished AS (
SELECT workpiece_type, current_procedure, procedure_result, 1 AS status
FROM t_mvp_aau_result
WHERE workpiece_id IN (
SELECT workpiece_id
FROM t_mvp_aau_result
WHERE station_id = '1'
ORDER BY starttime DESC
LIMIT 1
)
ORDER BY starttime DESC
),
checking AS (
SELECT workpiece_type, next_procedure AS current_procedure, 0 AS procedure_result, 0 AS status
FROM t_mvp_aau_procedure
WHERE current_procedure IN (
SELECT current_procedure
FROM finished
LIMIT 1
)
),
other AS (
SELECT workpiece_type, current_procedure, 0 AS procedure_result, -1 AS status
FROM t_mvp_aau_procedure
WHERE current_procedure NOT IN (
SELECT current_procedure
FROM finished
)
AND current_procedure NOT IN (
SELECT current_procedure
FROM checking
)
)
SELECT * FROM finished
UNION
SELECT * FROM checking
UNION
SELECT * FROM other
WITH finished AS (
SELECT workpiece_type, current_procedure, procedure_result, 1 AS status
FROM t_mvp_aau_result
WHERE workpiece_id IN (
SELECT workpiece_id
FROM t_mvp_aau_result
WHERE station_id = '1'
ORDER BY starttime DESC
LIMIT 1
)
ORDER BY starttime DESC
),
checking AS (
SELECT workpiece_type, next_procedure AS current_procedure, 0 AS procedure_result, 0 AS status
FROM t_mvp_aau_procedure
WHERE current_procedure IN (
SELECT current_procedure
FROM finished
LIMIT 1
)
),
other AS (
SELECT workpiece_type, current_procedure, 0 AS procedure_result, -1 AS status
FROM t_mvp_aau_procedure
WHERE current_procedure NOT IN (
SELECT current_procedure
FROM finished
)
AND current_procedure NOT IN (
SELECT current_procedure
FROM checking
)
)
SELECT * FROM finished
UNION
SELECT * FROM checking
UNION
SELECT * FROM other
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment