* 方法2:
* 测试数据和表格式
create cursor 课程表(节次 I,课程 C(30),星期 C(20),班级ID I,备注 C(250))
insert into 课程表 values(1,"语文","星期一",1001,"1001班课程表")
insert into 课程表 values(1,"语文","星期二",1001,"1001班课程表")
insert into 课程表 values(1,"语文","星期三",1001,"1001班课程表")
insert into 课程表 values(1,"数学","星期四",1001,"1001班课程表")
insert into 课程表 values(1,"数学","星期五",1001,"1001班课程表")
insert into 课程表 values(2,"英语","星期一",1001,"1001班课程表")
insert into 课程表 values(2,"英语","星期二",1001,"1001班课程表")
insert into 课程表 values(2,"英语","星期三",1001,"1001班课程表")
insert into 课程表 values(2,"物理","星期四",1001,"1001班课程表")
insert into 课程表 values(2,"物理","星期五",1001,"1001班课程表")
BROWSE
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
* 打印前 ,先转换,只打印 1001 班级的课程表
n班级=1001
SELECT T0.节次,T1.星期一,T2.星期二,T3.星期三,T4.星期四,T5.星期五,T6.星期六,T7.星期日 ;
FROM (SELECT DISTINCT 节次,班级ID FROM 课程表) as T0 ;
LEFT JOIN (SELECT 课程 as 星期一,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期一") as T1 ;
ON T0.班级ID=T1.班级ID AND T0.节次=T1.节次 ;
LEFT JOIN (SELECT 课程 as 星期二,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期二") as T2 ;
ON T0.班级ID=T2.班级ID AND T0.节次=T2.节次 ;
LEFT JOIN (SELECT 课程 as 星期三,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期三") as T3 ;
ON T0.班级ID=T3.班级ID AND T0.节次=T3.节次 ;
LEFT JOIN (SELECT 课程 as 星期四,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期四") as T4 ;
ON T0.班级ID=T4.班级ID AND T0.节次=T4.节次 ;
LEFT JOIN (SELECT 课程 as 星期五,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期五") as T5 ;
ON T0.班级ID=T5.班级ID AND T0.节次=T5.节次 ;
LEFT JOIN (SELECT 课程 as 星期六,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期六") as T6 ;
ON T0.班级ID=T5.班级ID AND T0.节次=T5.节次 ;
LEFT JOIN (SELECT 课程 as 星期日,节次,班级ID FROM 课程表 WHERE ALLTRIM(星期)="星期日") as T7 ;
ON T0.班级ID=T5.班级ID AND T0.节次=T5.节次 ;
WHERE T0.班级ID=n班级 ORDER BY T0.班级ID,T0.节次 INTO CURSOR TMP_课程表
BROWSE
图片附件: 游客没有浏览图片的权限,请
登录 或
注册