易截截图软件、单文件、免安装、纯绿色、仅160KB

sql 经典一

1.建表
create table temp(rq varchar(10),shengfu nchar(1))
2.插入数据
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-10','胜')
insert into temp values('2005-05-10','负')
insert into temp values('2005-05-10','负')
3.sql
select rq as '日期',sum(case when shengfu ='胜'  then 1 else 0 end) as '胜' ,sum(case when shengfu='负' then 1 else 0 end)  as '负' from temp group by rq
4.测试一下吧。。
     日期            胜    负
  2005-05-09   2     2
  2005-05-10   1     2


相关文档:

SQL语句PART11


1. My test: (create and grant the sysdba to a new user by SQL*Plus)
CREATE USER FJTEST1 IDENTIFIED BY JEANJEANFANG;
GRANT SYSDBA TO FJTEST;
REVOKE SYSDBA from FJTEST;
CONNECT FJTEST1/JEANJEANFANG AS SYSDBA;
2. Using ORAPWD in windows:
C:\» ORAPWD;
(show help information)
3. to see th ......

SQL Server 经常用到的几个设置选项

1. SET DEADLOCK_PRIORITY
说明:控制在发生死锁情况时会话的反应方式。如果两个进程都锁定数据,并且直到其它进程释放自己的锁时,每个进程才能释放自己的锁,即发生死锁情况。
语法:SET DEADLOCK_PRIORITY { LOW | NORMAL | @deadlock_var }
参数:LOW   ......

SQL去除某一字段值重复记录的方法

原理:对需要去重复记录的字段按组排序,然后取其中一条记录。在总查询语句中使用in语法过滤
去掉重复记录
select * from company where comid in (select Max(comid) from company group by companyname)
得到重复记录数
select * from company where comid not in (select Max(comid) from company group by companyn ......

动态SQL基本语法

 1 :普通SQL语句可以用exec执行
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname fr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号