- 浏览: 229883 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
thepastsee:
304572183股票交流 欢迎加入
实时股票 -
345161974:
很不错,我第一个接触的CSS卡片布局效果,多谢
css卡片效果
网上的都是一些静态的,用CASE WHEN结构实现。所以我写了一个动态的。
SP 代码:DELIMITER $$
DROP
PROCEDURE IF EXISTS `test`
.
`sp_row_column_wrap`
$
$
CREATE
DEFINER=
`root`
@
`localhost`
PROCEDURE `sp_row_column_wrap`
(
IN
$schema_name varchar
(
64)
,
IN
$table_name varchar
(
64)
)
BEGIN
declare cnt int
(
11)
;
declare $table_rows int
(
11)
;
declare i int
(
11)
;
declare j int
(
11)
;
declare s int
(
11)
;
declare str varchar
(
255)
;
-- Get the column number of the table
select
count
(
1)
from
information_schema.
columns where
table_schema=
$
schema_name and
table_name=
$
table_name into
cnt;
-- Get the row number of the table
select
table_rows from
information_schema.
tables where
table_schema =
$schema_name and
table_name=
$
table_name into
$table_rows;
-- Check whether the table exists or not
drop
table
if exists test.
temp;
create
table
if not
exists test.
temp (
`1`
varchar
(
255)
not
null
)
;
-- loop1 start
set
i =
0;
loop1:loop
if i =
$table_rows-1 then
leave loop1;
end
if;
set
@
stmt1
=
concat
(
'alter table test.temp add `'
,
i+
2,
'` varchar(255) not null'
)
;
prepare s1 from
@
stmt1
;
execute s1;
deallocate prepare s1;
set @stmt1 = '';
set
i =
i +
1;
end
loop loop1;
-- loop1 end;
set
s =
0;
-- loop2 start
loop2:loop
-- leave loop2
if s=
cnt then
leave loop2;
end
if;
set
@
stmt2
=
concat
(
'select column_name from information_schema.columns where table_schema="'
,
$
schema_name,
'" and table_name="'
,
$
table_name,
'" limit '
,
s,
',1 into @temp;'
)
;
prepare s2 from
@
stmt2
;
execute s2;
deallocate prepare s2;
set @stmt2 = '';
set
j=
0;
set
str =
' select '
;
-- Loop3 start
loop3:loop
if j =
$table_rows then
leave loop3;
end
if;
set
@
stmt3
=
concat
(
'select '
,
@
temp
,
' from '
,
$
schema_name,
'.'
,
$
table_name,
' limit '
,
j,
',1 into @temp2;'
)
;
prepare s3 from
@
stmt3
;
execute s3;
set
str =
concat
(
str,
'"'
,
@
temp2
,
'"'
,
','
)
;
deallocate prepare s3;
set @stmt3 = '';
set
j =
j+
1;
end
loop loop3;
set
str =
left
(
str,
length
(
str)
-
1)
;
-- insert new data into table
set
@
stmt4
=
concat
(
'insert into test.temp'
,
str,
';'
)
;
prepare s4 from
@
stmt4
;
execute s4;
deallocate prepare s4;
set @stmt4 = '';
set
s=
s+
1;
end
loop loop2;
END
$
$
DELIMITER ;
以下是测试结果:
======
select * from a;
select * from b;
select * from salary;
call sp_row_column_wrap('test','a');
select * from test.temp;
call sp_row_column_wrap('test','b');
select * from test.temp;
call sp_row_column_wrap('test','salary');
select * from test.temp;
query result(2 records)
aid | title |
1 | 111 |
2 | 222 |
query result(3 records)
bid | aid | image | time |
1 | 2 | 1.gif | 2007-08-08 |
2 | 2 | 2.gif | 2007-08-09 |
3 | 2 | 3.gif | 2007-08-08 |
query result(7 records)
id | cost | des | Autoid |
1 | 10 | aaaa | 1 |
1 | 15 | bbbb | 2 |
1 | 20 | cccc | 3 |
2 | 80 | aaaa | 4 |
2 | 100 | bbbb | 5 |
2 | 60 | dddd | 6 |
3 | 500 | dddd | 7 |
query result(2 records)
1 | 2 |
1 | 2 |
111 | 222 |
query result(4 records)
1 | 2 | 3 |
1 | 2 | 3 |
2 | 2 | 2 |
1.gif | 2.gif | 3.gif |
2007-08-08 | 2007-08-09 | 2007-08-08 |
query result(4 records)
1 | 2 | 3 | 4 | 5 | 6 | 7 |
1 | 1 | 1 | 2 | 2 | 2 | 3 |
10 | 15 | 20 | 80 | 100 | 60 | 500 |
aaaa | bbbb | cccc | aaaa | bbbb | dddd | dddd |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
发表评论
-
mysql_group by 奇怪问题解决
2011-10-22 13:32 954我回去查了一下关于mysql group by 奇怪的现像, ... -
mysql 密码
2011-09-26 17:46 739linux ---- ... -
转___MySQL Order By索引优化
2011-09-26 17:23 939MySQL Order By索引优化 ... -
mysql调优_20转
2011-06-22 15:24 705http://coolshell.cn/articles ... -
数据库设计
2011-06-22 11:43 658http://www.cnblogs.com/DBFocus/ ... -
MySQL索引的索引长度问题
2011-06-07 21:11 942转 http://blog.haohtml.com/a ... -
mysql_error_code
2011-05-13 21:44 741原创 mysql出错代码及 ... -
sql之left join、right join、inner join的区别_转
2011-04-17 23:37 860http://www.cnblogs.com/pcjim ... -
mysql_p150 error_转
2011-04-17 21:06 740ERROR ... -
mysql_序列表_02
2011-03-27 11:08 664lkjlkj -
mysql_投档项目终结
2011-03-21 21:41 612kljljlkj;lkj -
mysql_批量数据脚本..
2011-03-21 20:29 783lkjlkj -
window 启动仃止mysql
2011-03-17 23:32 937[导读]在非NT版本的Windows中,在后台启动mysqld ... -
flush privileges 意思_转转转
2011-03-17 23:31 1447test是mysql安装好后,就有的一个示例数据库 楼主可以 ... -
mysql 权限列表_转转
2011-03-17 23:30 995菜鸟课堂:MySQL权限的详细解答 2009-09-02 1 ... -
mysql 存储过程参数_可能乱码
2011-03-17 01:25 736DELIMITER $$ DROP PROCEDURE ... -
mysql存储过程_游标_项目练习
2011-03-17 01:04 848;lk;kl;kl;lk -
mysql 权限管理_转转转
2011-03-15 22:21 1030Mysql用户与权限管理 ... -
给mysql加上 rownum _转
2011-03-12 23:01 1379转 http://home.21cto.com/foru ... -
MYSQL中删除重复记录的方法_zhuanzhuan
2011-03-05 18:48 840在实际应用中,很可能会碰到一些需要删除某些字段的重复记录, ...
相关推荐
pdf转txt格式,可以将pdf转换成txt格式的小程序,
bai_zhuan=(int)zhuan/100; shi_zhuan=(int)zhuan0/10; ge_zhuan=(int)zhuan; write_data(table[bai_fen]); write_data(table[shi_fen]); write_data(table[ge_fen]); write_data(table[12]); write...
重构是迅速发现并修复有问题的代码的一种高效的方式。在《代码重构(c # & asp.net版)》中首次提供了在c#和asp.net中进行重构的专业方法,您将学习如何运用重构技术管理和修改代码
旋转LED 实现自适应转速 字幕滚动 对接的程序
mapgis二次开发转为jpg的功能,可以完美转换mapgis图形为jpg光栅图。
EH4生成的Z文件转V8格式的SEC文件
Android游戏源码最简单的打砖块游戏
Cadence转Altium Designe allegro .brd文件转成AD .pcbdoc文件 1、将.brd文件生成.alg文件 2、使用AD导入向导将.alg文件生成 .pcbdoc文件 由于PCB工程师或者硬件工程师使用的软件不同,经常需要在各种PCB绘制软件...
基于labview的转速测量,通过程序框图实现测速功能
rslidar雷达数据转velodyne数据功能包
主要用于路径规划,程序读入之初,需要先读入Kinect相机拍摄的深度图像。
是蚂蚁集团开源的基于 Spring Boot 的研发框架,它在 Spring Boot 的基础上,提供了诸如 Readiness Check,类隔离,日志空间隔离等等能力。
本人转的别人写的人工神经网络的学习体会与感受,真是受益匪浅啊!
用穷举法解决以下问题:36块砖,36人搬,男搬4,女搬3,两个小孩抬1砖。要求一次全搬完,问男、女、小孩有多少?
Deep Snake for Real-Time Instance Segmentation pytorch1.0 cuda8转6个pt
soho网络zhuan钱的体会.doc
Delphi 将Foxpro表转换为Paradox表,可能不太常用,不过也算是一个简单的数据库格式转换程序吧,或许对编写数据库开发程序有些许帮助。注:本程序运行后会直接读取DBF文件,若DBF报表文件不存在,程序会弹出错误信息...
该程序采用GFF3或GTF(基于1)格式的输入基因组注释,并将特定特征转换为6列BED格式(基于0),同时保留注释文件属性列的任何所需字段。 当需要围绕特定特征和唯一ID的基因组间隔时,此功能很有用。 它还可以在每个...
可以很方便的进行JS/HTML/ASP的代码互相转换
讲xlsx文件的课表,转成ics格式,然后就可以批量的将课表添加到日历中。以实现对生活更有逻辑的管理