//结构:select 子句 [into 子句] from 子句 [where 子句] [group by 子句] [having 子句] [order by 子句]
select dept_code,count(*) from oh_corp_info
where create_date>'2006-01-01'
group by dept_code having count(dept_code)>1 order by dept_code
//查询前百分之N的数据
select top 10 percent * from oh_corp_info
//查询语句between用法
select * from oh_corp_info where create_date between '2012-01-02' and '2012-03-01'
//异步服务器获取数据并且插入新表
insert into dbo.assess_company_project_v(a,b,c)
select a,b,c from opendatasource ('SQLOLEDB','Data Source=IP地址(例192.168.5.117);User ID=服务器;Password=123456;').newcq.dbo.assess_company_project_v
//打开异步服务器连接
[sql] view plaincopy
01.exec sp_configure 'show advanced options',1
02.reconfigure
03.exec sp_configure 'Ad Hoc Distributed Queries',1
04.reconfigure
//使用完成后,关闭Ad Hoc Distributed Queries:
[sql] view plaincopy
01.exec sp_configure 'Ad Hoc Distributed Queries',0
02.reconfigure
03.exec sp_configure 'show advanced options',0
04.reconfigure
本文介绍SQL查询的高级技巧,包括使用group by进行数据汇总,查询特定百分比的数据,以及between条件的运用。此外,还详细讲解了如何通过异步服务器获取数据并插入新表的方法,提供了具体的SQL语句和配置步骤。
1316

被折叠的 条评论
为什么被折叠?



