精典SQL语句
分类统计总数并排序多表联合查询的两种方法
例:
查询地区表中各省下面城市总数,并对查询结果取前十名
法一:
select b.id,a.[name],b.counts from n_area a,(select top 10 parent_id as id,sum(parent_id) as counts from n_area where parent_id<>0 group by parent_id order by sum(parent_id) desc
) b where a.id=b.id
法二:
select top 10 a.id,a.[name],(select count(*) from n_area b where b.parent_id=a.id ) as counts from n_area a where a.parent_id=0 order by counts desc
例:
查询发贴表中回复数最多的前十条发贴,(发帖与回帖同一表,查询出发帖主题,发帖ID,发帖人(另表),回帖数)
select a.mid,a.mtitle,(select c.uimg from BBS_Power c where c.uid=a.uid and c.uclass=a.uclass) as img from BBS_Msg a,(select top 10 partenID as id,sum(partenID) as counts from BBS_Msg where partenID<>0 group by partenID order by sum(partenID) desc) b where a.mid=b.id
相关文档:
SELECT LEFT(RTRIM('20080927p1058'),LEN('20080927p1058')-2)
SELECT SUBSTRING('20080927p1058',1,LEN('20080927p1058')-2)
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*whit ......
胡辉:13028803715 0755-82945017
9、深圳microsoft Windows 2003 Server报价 中文标准版5用户 4100
10、深圳microsoft Windws 2003 Server报价 中文企业版25用户 20500
11、深圳microsoft Windows 2008 Server报价 中文标准版5用户 580 ......
一、基础
1、说明:创建数据库
CREATE DATABASE database-name
2、说明:删除数据库
drop database dbname
3、说明:备份sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- 开始 备份
BACKUP DATABASE pubs TO testBack
4、说 ......
给大家个学习数据库的软件吧,sql server 2008,这个是微软公司的作品,不错,应该是非常不错,在电脑上安装Oracle数据库的话,那个比较大,而且在网上也不好下载,要是连接到学校服务器的话,也是不可能的,除非大家经常去机房上机,但是那个也不开,废话不多说了,大家去微软官网下载一个sql server 2008的试用版的安装文 ......
<%
set conn= server.createobject("ADODB.connection")
conn.open "driver={sybase driver 10};"
"srvr=SYBASE;"
"UID=sa;"
"pwd=sybase;"
sql="select no from tab_st ......