Last active
February 12, 2020 14:07
-
-
Save workze/c72befcef129aaba94bcfb4be71771a5 to your computer and use it in GitHub Desktop.
all about sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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