commit 6b94927ea34790958adbfcfe7e945794d9429d3c parent 23a7fbea6a0edf476a8c26074c6c8d60847a200e Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Mon, 10 Jul 2023 08:42:48 -0500 Completed consecutive numbers in a better way Diffstat:
| A | consecutive-numbers/consecutive-numbers1.sql | | | 8 | ++++++++ |
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/consecutive-numbers/consecutive-numbers1.sql b/consecutive-numbers/consecutive-numbers1.sql @@ -0,0 +1,8 @@ +--Better solution that uses joins +SELECT DISTINCT a.num ConsecutiveNums +FROM Logs AS a +LEFT JOIN Logs b +ON a.id + 1 = b.id +LEFT JOIN Logs c +ON b.id + 1 = c.id +WHERE a.num = b.num AND b.num = c.num