Advertisement
Guest User

Untitled

a guest
Jul 11th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. DROP DATABASE IF EXISTS `trainings`;
  2.  
  3. CREATE DATABASE `trainings`
  4. CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  5.  
  6. USE `trainings`;
  7.  
  8. DROP TABLE IF EXISTS `training_centers`;
  9.  
  10. CREATE TABLE `training_centers` (
  11. `id` int(11) NOT NULL AUTO_INCREMENT,
  12. `name` varchar(45) NOT NULL,
  13. `description` text,
  14. `url` varchar(2083),
  15. PRIMARY KEY (`id`)
  16. );
  17.  
  18. DROP TABLE IF EXISTS `courses`;
  19.  
  20. CREATE TABLE `courses` (
  21. `id` int(11) NOT NULL AUTO_INCREMENT,
  22. `name` varchar(100) NOT NULL,
  23. `description` text,
  24. PRIMARY KEY (`id`)
  25. );
  26.  
  27. DROP TABLE IF EXISTS `courses_timetable`;
  28.  
  29. CREATE TABLE `timetable` (
  30. `id` int(11) NOT NULL AUTO_INCREMENT,
  31. `course_id` int(11) NOT NULL,
  32. `training_center_id` int(11) NOT NULL,
  33. `start_date` date NOT NULL,
  34. PRIMARY KEY (`id`),
  35. CONSTRAINT `fk_courses_timetable_courses`
  36. FOREIGN KEY (`course_id`)
  37. REFERENCES `courses` (`id`),
  38. CONSTRAINT `fk_courses_timetable_training_centers`
  39. FOREIGN KEY (`training_center_id`)
  40. REFERENCES `training_centers` (`id`)
  41. );
  42.  
  43. INSERT INTO `training_centers` VALUES
  44. (1, 'Sofia Learning', NULL, 'http://sofialearning.org'),
  45. (2, 'Varna Innovations & Learning', 'Innovative training center, located in Varna. Provides trainings in software development and foreign languages', 'http://vil.edu'),
  46. (3, 'Plovdiv Trainings & Inspiration', NULL, NULL),
  47. (4, 'Sofia West Adult Trainings', 'The best training center in Lyulin', 'https://sofiawest.bg'),
  48. (5, 'Software Trainings Ltd.', NULL, 'http://softtrain.eu'),
  49. (6, 'Polyglot Language School', 'English, French, Spanish and Russian language courses', NULL),
  50. (7, 'Modern Dances Academy', 'Learn how to dance!', 'http://danceacademy.bg');
  51.  
  52. INSERT INTO `courses` VALUES
  53. (101, 'Java Basics', 'Learn more at https://softuni.bg/courses/java-basics/'),
  54. (102, 'English for beginners', '3-month English course'),
  55. (103, 'Salsa: First Steps', NULL),
  56. (104, 'Avancée Français', 'French language: Level III'),
  57. (105, 'HTML & CSS', NULL),
  58. (106, 'Databases', 'Introductionary course in databases, SQL, MySQL, SQL Server and MongoDB'),
  59. (107, 'C# Programming', 'Intro C# corse for beginners'),
  60. (108, 'Tango dances', NULL),
  61. (109, 'Spanish, Level II', 'Aprender Español');
  62.  
  63. INSERT INTO `timetable`(course_id, training_center_id, start_date) VALUES
  64. (101, 1, '2015-01-31'), (101, 5, '2015-02-28'),
  65. (102, 6, '2015-01-21'), (102, 4, '2015-01-07'), (102, 2, '2015-02-14'), (102, 1, '2015-03-05'), (102, 3, '2015-03-01'),
  66. (103, 7, '2015-02-25'), (103, 3, '2015-02-19'),
  67. (104, 5, '2015-01-07'), (104, 1, '2015-03-30'), (104, 3, '2015-04-01'),
  68. (105, 5, '2015-01-25'), (105, 4, '2015-03-23'), (105, 3, '2015-04-17'), (105, 2, '2015-03-19'),
  69. (106, 5, '2015-02-26'),
  70. (107, 2, '2015-02-20'), (107, 1, '2015-01-20'), (107, 3, '2015-03-01'),
  71. (109, 6, '2015-01-13');
  72.  
  73. UPDATE `timetable` t
  74. JOIN `courses` c ON t.course_id = c.id
  75. SET t.start_date = DATE_SUB(t.start_date, INTERVAL 7 DAY)
  76. WHERE c.name REGEXP '^[a-j]{1,5}.*s$';
  77.  
  78. SELECT
  79. tc.name AS `traning center`,
  80. t.start_date AS `start date`,
  81. c.name AS `course name`,
  82. c.description AS `more info`
  83. FROM `timetable` t
  84. JOIN `courses` c ON t.course_id = c.id
  85. JOIN `training_centers` tc ON t.training_center_id = tc.id
  86. ORDER BY t.start_date, t.id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement