易截截图软件、单文件、免安装、纯绿色、仅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语句PART8

PairWise subquery:
e.g.:
select * from wf_docsort where (ndocsortid,nmoduleinfoid)  in (select ndocsortid, nmoduleinfoid from wf_docsort where instr(cname,'文')>0)
the above sql is the same function as:
select * from wf_docsort where ndocsortid = (select ndocsortid from wf_docsort where ......

SQL语句PART10

oracle tips
Exist的用法:
select gw.ndocid from 
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2。把GW表和SN表里相同的NDOCID显示出来
select gw.ndocid from 
(se ......

sql server中in和exists的小区别 oracle未测试

in 的话, 如果是null 就不比较了,既不是in 也不是 not in
exists的话 因为用 = 加在条件里比较了,所以 null 是 not exists
select *
from pricetemp
where cast(商品コード as varchar(10))not in(
           select shohin_cd
  &nbs ......

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号