開發(fā)過程中遇到個mysql的問題,我有多個表,多個表之間有聯(lián)系,每個表都有單獨的排序。
course > course_level > course_unit > course_lesson,這四個表的層級關(guān)系就是課程下面很多l(xiāng)evel,每個level下面有多個unit,每個unit下面有多個lesson,所有表的排序字段均為sort,全部是按照升序排列,如果某個級別sort相同,就按照id升序排列,例如level表里面id=5的sort是0,id=10的sor也是0,那么id5就排在前,每個子級別下的sort互不干擾,例如,course_unit表里面的course_level_id=2,和course_level_id=5的unit都會出現(xiàn)sort=0,sort=5的情況,意思就是下級的排序和上級的排序相關(guān)聯(lián)。
現(xiàn)在我需要根據(jù)course,course_level,course_unit的順序來把course_lesson的順序確定下來,就是整個課程體系的id排序,請問這個mysql語句怎么寫?lesson_id大概有1000個,只需要排好序的course_lesson表里面的id字段。
#課程分類表
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`course_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '課程類型(1.語文;2.數(shù)學(xué);)',
`lesson_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '課堂類型(0.一對一試聽課;1.一對一小班課;2.一對一大班課;3.一對多小班課;4.一對多大班課;5.一對多小班試聽課)',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT '課程名',
`level_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '該課程下總級別數(shù)量',
`unit_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '該Level下總unit數(shù)',
`lesson_num` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '該level下總lesson數(shù)',
`lesson_class_hour` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '該Level下所有Lesson總學(xué)時(分鐘)',
`class_hour` int(8) DEFAULT '25' COMMENT '當(dāng)前課程每節(jié)課的上課時長',
`lesson_before_time` int(8) DEFAULT '5' COMMENT '課前備課時間(分鐘)',
`lesson_after_time` int(8) DEFAULT '5' COMMENT '課后休息時間(分鐘)',
`lesson_interval_time` int(8) DEFAULT '15' COMMENT '課程間隔時間(分鐘)',
`sort` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '排序順序,升序排列',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '狀態(tài)(1.正常;2.過期;3.無效;4.刪除)',
`creator` int(11) unsigned NOT NULL,
`updator` int(11) unsigned NOT NULL DEFAULT '0',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`teacher_absence_time` int(8) DEFAULT '15' COMMENT '判定老師上課缺席時間',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='課程信息表';
#課程等級表
DROP TABLE IF EXISTS `course_level`;
CREATE TABLE `course_level` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'LevelId',
`course_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '課程Id',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'level名稱,規(guī)則為level1~level6,名稱固定不變',
`title` varchar(64) NOT NULL DEFAULT '' COMMENT 'Level標(biāo)題',
`unit_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '該Level下總unit數(shù)',
`lesson_num` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '該level下總lesson數(shù)',
`lesson_class_hour` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '該Level下所有Lesson總學(xué)時(分鐘)',
`sort` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '排序順序,升序排列',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Level狀態(tài)(1.正常;2.過期;3.無效;4.刪除)',
`creator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '創(chuàng)建者',
`updator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新者',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='課程下Level信息表';
#單元表
DROP TABLE IF EXISTS `course_unit`;
CREATE TABLE `course_unit` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'LevelId',
`course_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '所屬courseId',
`course_level_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '課程Id',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT '單元名',
`title` varchar(64) NOT NULL DEFAULT '' COMMENT '單元主題名',
`lesson_num` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '該單元下lesson數(shù)',
`lesson_class_hour` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '該單元下所有l(wèi)esson總學(xué)時(分鐘)',
`sort` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '排序順序,升序排列',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Level狀態(tài)(1.正常;2.過期;3.無效;4.刪除)',
`creator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '創(chuàng)建者',
`updator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新者',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8 COMMENT='課程下單元信息表';
#課程表
DROP TABLE IF EXISTS `course_lesson`;
CREATE TABLE `course_lesson` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'LevelId',
`course_id` int(11) unsigned NOT NULL,
`course_level_id` int(11) unsigned NOT NULL,
`course_unit_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '課程Id',
`courseware_id` int(11) NOT NULL DEFAULT '0' COMMENT '課件ID',
`preview_video_id` tinyint(3) NOT NULL DEFAULT '0' COMMENT '課前預(yù)習(xí)視頻',
`reference_video_id` tinyint(3) NOT NULL DEFAULT '0' COMMENT '課程參考教學(xué)視頻id',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'level名稱,規(guī)則為level1~level6,名稱固定不變',
`title` varchar(64) NOT NULL DEFAULT '' COMMENT '課程標(biāo)題',
`topic` varchar(64) NOT NULL DEFAULT '' COMMENT '課程主題',
`subject` text NOT NULL COMMENT '課程目標(biāo)',
`class_hour` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '課程學(xué)時(分鐘)',
`sort` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '排序順序,升序排列',
`status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Level狀態(tài)(1.正常;2.過期;3.無效;4.刪除)',
`creator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '創(chuàng)建者',
`updator` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新者',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=763 DEFAULT CHARSET=utf8 COMMENT='課程下Lesson信息表';
SELECT cls.id AS lesson_id,
c.id AS course_id,
cl.id AS course_level_id,
cu.id AS course_unit_id
FROM course c
INNER JOIN course_level cl
ON c.id = cl.course_id
INNER JOIN course_unit cu
ON c.id = cu.course_id
AND cl.id = cu.course_level_id
INNER JOIN course_lesson cls
ON c.id = cls.course_id
AND cl.id = cls.course_level_id
AND cu.id = cls.course_unit_id
ORDER BY c.sort, c.id,
cl.sort, cl.id,
cu.sort, cu.id,
cls.sort, cls.id
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。