This video is the beginning portion of a much larger video where I will cover how I used sql code to generate data for a puzzle book. In this particular video, I cover IF EXISTS, DROP TABLE, SELECT INTO, INSERT INTO, SYSOBJECTS, XTYPE, and certain errors that you will need to look out for.
Link to my SQL Courses on Udemy: https://www.udemy.com/course/sql-serv...
--******************************************************************************************************************************************************
-- This is the sql code that allowed me to come up with my 720 combination of 1 to 6.
--******************************************************************************************************************************************************
USE StepSums
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'A' AND xtype = 'u')
DROP TABLE dbo.A
--------------------------------------------------------------------------
SELECT '1' A INTO A
INSERT INTO A SELECT '2'
INSERT INTO A SELECT '3'
INSERT INTO A SELECT '4'
INSERT INTO A SELECT '5'
INSERT INTO A SELECT '6'
--SELECT * FROM A
--------------------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'StepSums_06_PuzzleMap' AND xtype = 'u')
DROP TABLE dbo.StepSums_06_PuzzleMap
--------------------------------------------------------------------------------------------
SELECT a1 [Position 1],
a2 [Position 2],
a3 [Position 3],
a4 [Position 4],
a5 [Position 5],
a6 [Position 6]
INTO StepSums_06_PuzzleMap
FROM
(
SELECT *
FROM (SELECT A a1 FROM A) a1,
(SELECT A a2 FROM A) a2,
(SELECT A a3 FROM A) a3,
(SELECT A a4 FROM A) a4,
(SELECT A a5 FROM A) a5,
(SELECT A a6 FROM A) a6
WHERE a1.a1 != a2.a2 AND a1.a1 != a3.a3 AND a1.a1 != a4.a4 AND a1.a1 != a5.a5 AND a1.a1 != a6.a6
AND
a2.a2 != a3.a3 AND a2.a2 != a4.a4 AND a2.a2 != a5.a5 AND a2.a2 != a6.a6
AND
a3.a3 != a4.a4 AND a3.a3 != a5.a5 AND a3.a3 != a6.a6
AND
a4.a4 != a5.a5 AND a4.a4 != a6.a6
AND
a5.a5 != a6.a6
) x
ORDER BY 1, 2, 3, 4, 5, 6
SELECT * FROM StepSums_06_PuzzleMap ORDER BY 1, 2, 3, 4, 5, 6
Смотрите видео Real-World example of using SQL Server to assist in making a puzzle book!! онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь SQL University 01 Январь 1970, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 162 раз и оно понравилось 4 людям.