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

简单但有用的SQL脚本

行列转换
create table test(id int,name varchar(20),quarter int,profile int)
insert into test values(1,'a',1,1000)
insert into test values(1,'a',2,2000)
insert into test values(1,'a',3,4000)
insert into test values(1,'a',4,5000)
insert into test values(2,'b',1,3000)
insert into test values(2,'b',2,3500)
insert into test values(2,'b',3,4200)
insert into test values(2,'b',4,5500)
select * from test
--行转列
select id,name,
[1] as "一季度",
[2] as "二季度",
[3] as "三季度",
[4] as "四季度",
[5] as "5"
from
test
pivot
(
sum(profile)
for quarter in
([1],[2],[3],[4],[5])
)
as pvt
create table test2(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int)
insert into test2 values(1,'a',1000,2000,4000,5000)
insert into test2 values(2,'b',3000,3500,4200,5500)
select * from test2
--列转行
select id,name,quarter,profile
from
test2
unpivot
(
profile
for quarter in
([Q1],[Q2],[Q3],[Q4])
)
as unpvt

sql替换字符串 substring replace
--例子1:
update tbPersonalInfo set TrueName = replace(TrueName,substring(TrueName,2,4),'**') where ID = 1
--例子2:
update tbPersonalInfo set Mobile = replace(Mobile,substring(Mobile,4,11),'********') where ID = 1
--例子3:
update tbPersonalInfo set Email = replace(Email,'chinamobile','******') where ID = 1

SQL查询一个表内相同纪录 having
//如果一个ID可以区分的话,可以这么写
select * from 表 where ID in (
select ID from 表 group by ID having sum(1)>1)
//如果几个ID才能区分的话,可以这么写
select * from 表 where ID1+ID2+ID3 in
(select ID1+ID2+ID3 from 表 group by ID1,ID2,ID3 having sum(1)>1)
//其他回答:数据表是zy_bho,想找出ZYH字段名相同的记录
//方法1:
SELECT *from zy_bho a WHERE EXISTS
(SELECT 1 from zy_bho WHERE [PK] <> a.[PK] AND ZYH = a.ZYH)

//方法2:
select a.* from zy_bho a join zy_bho b
on (a.[pk]<>b.[pk] and a.zyh=b.zyh)

//方法3:
select * from zy_bbo where zyh in
(select zyh from zy_bbo group b


相关文档:

hibernate 多条件组合查询 之 sql 拼接

  public static void main(String[] args) {
      
       Session session = null;
       Transaction tx = null;
       List list = null;
     &nb ......

SQL Server全文索引的个人总结(上) 关于中文分词


SQL Server全文索引的个人总结(上) -关于中文分词
(2005-11-14 04:29:44)
转载
 
分类:深度研究
大家都知道LIKE查询很慢,全文索引就是事先做好相关的索引,表示哪个主题词可以在哪些记录里找到,甚至事先计算好RANK,检索时可以把相关度高的先列出来,这可以大大提高检索的速度。
打个比方,你有 ......

sql server中将自增长列归零

一个项目完成后数据库中会有很多无用的测试数据,可以使用delete * 将数据全部删除,但自增长列(一般是主键)基数不会归零,使用TRUNCATE函数可以将表中数据全部删除,并且将自增长列基数归零。一定要注意,表中的数据全部删除了。它的语法如下:
TRUNCATE TABLE tableName –其中tableName中所要操作的数据
......

sql server 2000卸载后,再次安装的问题

错误提示,有一个文件已经挂起,必须重新启动计算机。重新启动,再次安装仍然是同样的问题。
注册表键值的问题。解决方法:
只要删除\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\下的PendingFileRenameOperations键值,就可以重新安装了。
删除后安装,不必重新启动计算机。 ......

SQL常见查询问题(编程)


有些常见的问题在论坛中不断出现,不妨整理一下。
以下语句是在SQLServer2005上实现的,一些语句无法在SS2000上执行。
有用指数是我根据这个问题的常见程度打的分,仅供参考。实际上,当你遇到了这个问题,这个问题哪怕再少见,解决方案也是非常有用的。
1. 生成若干行记录
有用指数:★★★★★
常见的问题类型:根 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号