今天在工作的时候遇到了行列转换的问题,记得去年有一段时间经常写,但是许久不用已经记不太得了.好记性不如烂笔头,忙完之后赶紧记录一下. 关键字:PIVOT(行转列),UNPIVOT(列转行) 先说说 PIVOT(行转列)这是我今天遇到的问题 PIVOT(行专列) 主要语法:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 完整语法: table_source PIVOT( 聚合函数(value_column) FOR pivot_column IN(<column_list>)…
select OPER_TIME, MICROPAY, REFUND from ( select trunc(oper_time) oper_time, class_name, sum(total_fee) total_fee from wx_pay_detail group by trunc(oper_time),class_name ) pivot(sum(total_fee) for class_name in ('MicroPay'as "MICROPAY",'Refund'…
一.创建存储过程 if Exists(select name from sysobjects where NAME = 'sp1LoginUser' and type='P')drop procedure sp1LoginUserGOCREATE PROCEDURE [dbo].[sp1LoginUser]-- Add the parameters for the stored procedure here@username NVARCHAR(50)ASBEGINDECLARE @identit…