以下是引用yafengliang在2018-5-27 10:13:22的发言:
报表自动生成三行数据行,分别对应节次12,34,56。一门课一条记录如何定位到报表。
数据用上面的格式,很简单就能用VFP报表做出来。
* 方法1:直接用星期做字段,好处,直接查询后就可以
create cursor 课程表(节次 I,星期一 C(30),星期二 C(30),星期三 C(30),星期四 C(30),星期五 C(30),星期六 C(30),星期日 C(30),备注 C(250))
insert into 课程表 values(1,"语文","数学","英语","体育","语文","","","")
insert into 课程表 values(2,"数学","语文","数学","英语","语文","","","")
* 方法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班课程表")
* 打印前 ,先转换,只打印 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_课程表