班库(上海)商务咨询有限公司

有一个表叫Student, 含有以下字段:id, classid, name, birth, remark

1. 插入一条记录:classid=2 name=张三 birth=1982-07-19;

答案:insert into student (classid, name, birth) values(2, '张三', '1982-07-19')

 

2. 选出所有classid=4的学生;

答案:select * from student where classid=4

 

3. 查询所有班级出生年月大于1976的人;

答案:select * from student where birth>'1976'

 

4. 查询每个班级出生年月大于1976的人数;

答案:select classid, count(*) as number from student where birth>'1976' group by classid

 

5. 查询所有班级人数;

答案:select classid, count(*) as total from student group by classid

 

6. 查询所有REMAK中含有“计划”的记录;

答案:select * from student where remark like '%计划%'

 

7. 如果提高SQL的效率;

答案:在ASP中,

  • 使用JOIN写复杂的SQL语句代替一堆SQL语句:一次查询出所有数据;
  • 使用UPDATE语句代替rs.update();
  • 采用批量处理SQL语句比一句一句执行的效率高;
  • where子句中首先考虑索引;
  • 避免使用TEXT等大的字段:数据库大执行效率也大;

其他方面:

  • 使用内嵌视图代替临时表:临时表会消耗大量内存以及进行大量I/O操作;
  • 避免使用LEFT JOIN与NULL值,用INNER JOIN,并设置字段不能为NULL;
  • 使用索引;
  • 使用分区视图;
  • 使用触发器跑存储过程到另外一张统计表里;

 

8. 代码实现打印扬辉三角形;

答案:

 

Code
posted @ 2008-08-30 02:22  Fernando  阅读(440)  评论(1编辑  收藏  举报