SQL CASE的用法,比想象中的强大
表如下
一条语句显示所有大于25岁和下的人,以上的人显'大龄'
select case when age>25 then '大龄' else '小龄' end as 年龄级别,count(*) as 人数 from infor group by case when age>25 then '大龄' else '小龄' end
相关文档:
项目中需要根据课件名称按月统计出访问的情况,第一次我采用了最土的一种办法,使用循环,给sql传递年月两个参数,
for(var y=2009;y<=2010;y++){
for(var m=1;m<=12;m++){
// todo : SQL 查询
}
}
这样,统计2 ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......
using System.Data.SqlClient;
using System.Data.OleDb;
private void tsmiImportTeacherInfo_Click(object sender, EventArgs e)
{
DataSet ds;
  ......
系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists
修改方法如下:
in的SQL语句
SELECT id, category_id, htmlfile, title, convert(varchar(20),begintime,112) as pubtime
from tab_oa_pub WHERE is_check=1 and
category_id in (sel ......