第一条sql: select unit,count(*)as number from archives_management group by unit 第二条sql: select fine_units,count(*) as fine_number from fine group by fine_units 注:两条sql 分别查询结果如下图 要求生成如下格式: unit number fine_num
select * from market//查看原来所有数据 //第一种方式 select max(case area when '南京' then num else 0 end) 南京, max(case area when '上海' then num else 0 end) 上海, max(case area when '无锡' then num else 0 end) 无锡 from market //第二种 SELECT * FROM ( SELECT * FROM market ) p
编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Byron Tardif 撰写. 当您开始一个新的 Web 项目,或者刚刚开始开发一般的网站和应用程序时,您可能希望从小处着手.但是,您可能不会停滞不前.在概念证明阶段,您可能不希望在新的 Web 场上耗费资源,但随着事业不断发展,您无法使用一小台服务器来实施大型市场营销活动.在 Windows Azure 网站的云中进行开发和部署时也一样. 在本博客文章中,我将向您介绍您可以采用的开发.测试和实施方式,同时控制好预算的时间
1.开始数据结构如下: 2.转为如下图: 使用如下SQL语句: ---横向转丛向 select name '姓名', max(case when course='语文' then score end) as '语文', max(case when course='数学' then score end) as '数学', max(case when course='物理' then score end) as '物理' from t_score group by name 3.以及转为如下图: (
使用过SQL Server 2000的人都知道,要想实现行列转换,必须综合利用聚合函数和动态SQL,具体实现起来需要一定的技巧,而在SQL Server 2005中,使用新引进的关键字PIVOT/UNPIVOT,则可以很容易的实现行列转换的需求. 在本文中我们将通过两个简单的例子详细讲解PIVOT和UNPIVOT的用法. PIVOT是行转列,用法如下: 假如表结构如下: id name quarter profile 1 a 1 10