Skip to content

Instantly share code, notes, and snippets.

@hobodave
Created November 7, 2011 19:07
Show Gist options
  • Select an option

  • Save hobodave/1345834 to your computer and use it in GitHub Desktop.

Select an option

Save hobodave/1345834 to your computer and use it in GitHub Desktop.
CREATE TABLE `survey_history` (
`schedule_history_id` int(11) NOT NULL AUTO_INCREMENT,
`schedule_id` int(11) NOT NULL DEFAULT '0',
`department_id` int(11) NOT NULL DEFAULT '0',
`iteration` int(11) NOT NULL DEFAULT '0',
`start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`due_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`completion_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`survey_user` int(11) NOT NULL DEFAULT '0',
`survey_id` int(11) NOT NULL DEFAULT '0',
`ticket_id` int(11) NOT NULL DEFAULT '0',
`survey_num` varchar(50) NOT NULL,
PRIMARY KEY (`schedule_history_id`),
KEY `fk_survey_history_survey_user` (`survey_user`),
KEY `fk_survey_history_ticket_id` (`ticket_id`),
KEY `fk_survey_history_department_id` (`department_id`)
) ENGINE=InnoDB;
UPDATE survey_history sh
JOIN answers a ON a.ticket_id = sh.ticket_id
JOIN sections s ON s.id = a.section_id
SET sh.survey_id = s.surveyCT_id
WHERE sh.survey_id <> s.surveyCT_id;
-- Query OK, 436 rows affected (1.12 sec)
-- Rows matched: 436 Changed: 436 Warnings: 0
SELECT sh.schedule_history_id, sh.survey_id, s.surveyCT_id, count(*)
FROM survey_history sh
JOIN answers a ON a.ticket_id = sh.ticket_id
JOIN sections s on a.section_id = s.id
WHERE sh.survey_id <> s.surveyCT_id
GROUP BY sh.schedule_history_id, sh.survey_id, s.surveyCT_id;
-- ...
-- 436 rows in set (0.93 sec)
-- Repeat Query 1
-- ...
--Query OK, 436 rows affected (1.12 sec)
--Rows matched: 436 Changed: 436 Warnings: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment