Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43618
  • 博文数量: 42
  • 博客积分: 2520
  • 博客等级: 少校
  • 技术积分: 610
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-10 13:46
文章分类
文章存档

2008年(42)

我的朋友
最近访客

分类:

2008-04-21 16:17:14

说明: 从数据库中去一年的各单位电话费统计(电话费定额贺电化肥清单两个表来源) 3TN7{d) ,  
  SQL: ~QUOBI{  
SELECT a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy') AS telyear, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '01', a.factration)) AS JAN, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '02', a.factration)) AS FRI, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '03', a.factration)) AS MAR, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '04', a.factration)) AS APR, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '05', a.factration)) AS MAY, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '06', a.factration)) AS JUE,SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '07', a.factration)) AS JUL, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '08', a.factration)) AS AGU, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '09', a.factration)) AS SEP, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '10', a.factration)) AS OCT, SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '11', a.factration)) AS NOV,SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '12', a.factration)) AS DEC FROM (SELECT a.userper, a.tel, a.standfee, b.telfeedate, b.factration FROM TELFEESTAND a, TELFEE b WHERE a.tel = b.telfax) a GROUP BY a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy')   of"d#_H]H  
说明:四表联查问题: \s=|0u  
SQL: select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....    UCoj|Z`t  
说明:得到表中最小的未使用的ID号 ';Gorn9p]  
SQL: SELECT (CASE WHEN EXISTS(SELECT * FROM Handle b WHERE b.HandleID = 1) THEN MIN(HandleID) + 1 ELSE 1 END) as HandleID FROM Handle WHERE NOT HandleID IN (SELECT a.HandleID - 1 FROM Handle a)  <\78W  
SQLSERVER2005系统数据库恢复 }6t%q{ W5  
SQLSERVER2005系统数据库恢复2007-08-22 13:24.SQLSERVER2005的系统数据库恢复与SQLSERVER2000略有不同,道理相通.下面我们先来看看master恢复的具体办法:C:\Documents and Settings\Administrator>osql -E1> restore database master from disk=‘d:\bak\master‘2> go已为数据库 ‘master‘,文件 ‘master‘ (位于文件 1 上)处理了 376 页。已为数据库 ‘master‘,文件 ‘mastlog‘ (位于文件 1 上)处理了 4 页。----------------------------------------------------------------至此master数据库恢复成功,进去看看吧。 * ZYYV% v  
一个SQL语句的问题:行列转换 $n=ujYwl  
select * from v_temp ng%ku0x69  
上面的视图结果如下: -LdLvjb  
user_name role_name @+3i }Y |\  
------------------------- {co$c0,   
系统管理员 管理员 JBP,iqG   
feng 管理员 ;P1?pmtB  
feng 一般用户 c?nza4  
test 一般用户  ,T[?b<  
想把结果变成这样: e:p  
user_name role_name ]"Vci Z+  
---------------------------  
系统管理员 管理员 UJX_\fljm  
feng 管理员,一般用户 #Nk9QHb  
test 一般用户 E5H="'z  
=================== n}P )ss  
create table a_test(name varchar(20),role2 varchar(20)) }'h~ C  
insert into a_test values('李','管理员') eN+1)+  
insert into a_test values('张','管理员') d W_] @  
insert into a_test values('张','一般用户') 1{OS8P?s2  
insert into a_test values('常','一般用户') p9R)T&  
w=}x 6BNM  
create function join_str(@content varchar(100)) XB~l  
returns varchar(2000) [k@O[s  
as 6Uwd'  
begin "ZP^YU4m7  
declare @str varchar(2000) E-AuBTu?E  
set @str='' eWw|Ndp  
select @str=@str+','+rtrim(role2) from a_test where [name]=@content 6D+O2RG%  
select @str=right(@str,len(@str)-1) Xy|<  
return @str `B#m')I  
end X aX7(s  
go XTxaGE  
--调用: F ] x(  
select [name],dbo.join_str([name]) role2 from a_test group by [name] 2=g?L93  
--select distinct name,dbo.uf_test(name) from a_test H3TQ9=_u%]  
快速比较结构相同的两表 uRK rsen  
结构相同的两表,一表有记录3万条左右,一表有记录2万条左右,我怎样快速查找两表的不同记录? [RZX09ppx  
============================ CLB08\+Jf  
给你一个测试方法,从northwind中的orders表取数据。 JIj+* N '  
select * into n1 from orders e]\XBO`,  
select * into n2 from orders wr2.L7 Q  
select * from n1  ~lR6O!  
select * from n2 @l.xGVn;>e  
--添加主键,然后修改n1中若干字段的若干条 ^y 
alter table n1 add constraint pk_n1_id primary key (OrderID) [!|1S0F  
alter table n2 add constraint pk_n2_id primary key (OrderID) 'W .6 u3  
select OrderID from (select * from n1 union select * from n2) a group by OrderID having count(*) > 1 PU8`!.`@  
应该可以,而且将不同的记录的ID显示出来。 8Oryw j  
下面的适用于双方记录一样的情况, T+B2Q3+:  
select * from n1 where orderid in (select OrderID from (select * from n1 union select * from n2) a group by OrderID having count(*) > 1) Zm8j}  
至于双方互不存在的记录是比较好处理的 )r'{d%0VJ  
--删除n1,n2中若干条记录  U4c%#+>*  
delete from n1 where orderID in ('10728','10730') r:)7t`I!  
delete from n2 where orderID in ('11000','11001') bR_piek  
vn>}}ea  
--*************************************************************
阅读(260) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~