SQL 查询横表变竖表】的更多相关文章

SQL 查询横表变竖表   /*普通行列转换 假设有张学生成绩表(tb)如下:Name Subject Result张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物理 94*/ -------------------------------------------------------------------------/*想变成 姓名         语文        数学        物理          ---------- --------…
一  竖表转横表 1. 首先创建竖表 create table student ( id varchar(32) primary key, name varchar (50) not null, subject varchar(50) not null, result int); 2.  插入数据 insert into student (id, name, subject, result) values ('0001', '小明', '语文', 83); insert into student…
竖表转横表 竖表结构: Name Course Grade 张三 语文 75 张三 数学 80 张三 英语 90 李四 语文 95 李四 数学 55 转换后横表结构: Name 语文 数学 英语 张三 75 80 90 李四 95 55 0 SQL语句: select Name, end) as 语文, end) as 数学, end) as 英语 from TableA group by Name 竖表转横表 横表转竖表 横表结构: ID Name Chinese Math English 1…
--sql查询  所有被锁定的表 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT' spid   锁表进程  tableName   被锁表名   解锁:   declare @spid  int  Set @spid  = 57 --锁表进程 declare @sql var…
SQL查询数据并插入新表 --如果接受数据导入的表已经存在 insert into 表 select * from tablename --如果导入数据并生成表 select * into 表 from tablename…
使用SQL查询所有数据库名和表名 MySQL中查询所有数据库名和表名 查询所有数据库 show databases; 1 1 查询指定数据库中所有表名 select table_name from information_schema.tables where table_schema='database_name' and table_type='base table'; 1 1 查询指定表中的所有字段名 select column_name from information_schema.c…
then d.name else null end) 表名, a.colorder 字段序号, a.name 字段名, ( then '√'else '' end) 标识, ( then '√' else '' end) 主键, b.name 类型, a.length 占用字节数, COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度, ) as 小数位数, ( then '√'else '' end) 允许空, isnull(e.text,'') 默认值,…
查询数据库 select * From master.dbo.sysdatabases where name='数据库名' and status<>512   --读取库中的所有表名 (当前数据库)select name from sysobjects where xtype='u' --读取指定表的所有列名 select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name…
select b.NativeName from sanleiDB.dbo.Dictionary_Native b where not EXISTS (select a.NativeName from Dictionary_Native a where a.NativeName = b.NativeName)union select a.NativeName from Dictionary_Native a where not exists (select b.NativeName from s…
SELECT sys.tables.name as TableName from sys.tables…