MYSQL :逗号分隔串表,分解成竖表
- DROP TEMPORARY TABLE IF EXISTS Temp_Num ;
- CREATE TEMPORARY TABLE Temp_Num ( xh INT PRIMARY KEY ); -- 创建数字辅助表
- SET @i = 0;
- INSERT INTO Temp_Num(xh) -- 写入数字辅助表
- SELECT @i := @i+1
- FROM AdDataCenter.`Ad_Targeting_Mobisage` a
- LIMIT 0, 100 ;
- SELECT b.AdGroupID , SUBSTRING( str_split , a.xh , LOCATE(',',CONCAT( str_split ,','), a.xh ) - a.xh ) AS splitstr
- FROM Temp_Num a
- CROSS JOIN
- (SELECT AppCategory AS str_split ,app.*
- FROM AdDataCenter.Ad_Targeting_Mobisage app
- WHERE app.AdTargetingID IN (1,2,3,4) ) b
- WHERE a.xh <= LENGTH( str_split )
- AND SUBSTRING( CONCAT(',', str_split ), a.xh, 1) = ','
- LIMIT 0 ,1000 ;
- SELECT AppCategory AS str_split ,app.*
- FROM AdDataCenter.Ad_Targeting_Mobisage app
- WHERE app.AdTargetingID IN (1,2,3,4);
原数据
str_split AdTargetingID
---------------------------------------------------------------------- ---------------
1,10,11,12,13,14,15,16,19,2,20,21,22,24,25,26,27,28,29,3,31,32,4,5,6,8 2
1,10,11,13,14,15,16,2,20,21,22,25,26,27,28,29,3,31,32,4,6,8 3
1,10,11,12,13,14,15,16,19,20,21,22,25,27,28,3,32,4,6,8 4
实现的效果是
AdGroupID splitstr
--------- ----------
2 1
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 19
2 2
2 20
2 21
2 22
2 24
2 25
2 26
2 27
2 28
2 29
2 3
2 31
2 32
2 4
2 5
2 6
2 8
3 1
3 10
3 11
3 13
3 14
3 15
3 16
3 2
3 20
3 21
3 22
3 25
3 26
3 27
3 28
3 29
3 3
3 31
3 32
3 4
3 6
3 8
4 1
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 19
4 20
4 21
4 22
4 25
4 27
4 28
4 3
4 32
4 4
4 6
4 8
MYSQL :逗号分隔串表,分解成竖表的更多相关文章
- Mysql 表转换成 Sqlite表
目前的转换仅仅支持对没有外键的Mysql数据表 准备: 下载安装 Sqlite Expert 软件 一 获取Mysql中的.sql文件,获取过程省略可以直接导出sql文件 二 在Sqlite Expe ...
- SQL竖表转换成横表统计
#创建表user_score create table user_score ( name varchar(20), subjects varchar(20), score int ); insert ...
- 20190321xlVBA_明细信息表汇总成数据表
刚开始能把代码敲得行云流水的时候,写代码是种乐趣.有了功利目的之后,重复的工作写多几次,厌烦的情绪四处弥漫. 去年八月份正好写了一回,还能支持控件,在此备忘. Public Sub Informati ...
- MySQL中横表和竖表相互转换
一 竖表转横表 1. 首先创建竖表 create table student ( id varchar(32) primary key, name varchar (50) not null, su ...
- .Net 将一个DataTable分解成多个DataTable
这两天遇到一个问题,我们所接触 的一个系统在导出数据到Excel的时候,产生了内存溢出的错误.原因在于数据过大,它导出是将所有数据存放在一个DataSet的一个表中,再将这个数 据集放入session ...
- mysql单个表拆分成多个表
一.横向拆分 create table 新表的名称 select * from 被拆分的表 order by id limit int1,int2 int1为其实位置,int2为几条 注意:这样拆分后 ...
- MySQL学习之——锁(行锁、表锁、页锁、乐观锁、悲观锁等)
转载. https://blog.csdn.net/mysteryhaohao/article/details/51669741 锁,在现实生活中是为我们想要隐藏于外界所使用的一种工具.在计算机中,是 ...
- MySQL之单表查询 一 单表查询的语法 二 关键字的执行优先级(重点) 三 简单查询 四 WHERE约束 五 分组查询:GROUP BY 六 HAVING过滤 七 查询排序:ORDER BY 八 限制查询的记录数:LIMIT 九 使用正则表达式查询
MySQL之单表查询 阅读目录 一 单表查询的语法 二 关键字的执行优先级(重点) 三 简单查询 四 WHERE约束 五 分组查询:GROUP BY 六 HAVING过滤 七 查询排序:ORDER B ...
- 面试官:为什么mysql不建议执行超过3表以上的多表关联查询?
概述 前段时间在跟其他公司DBA交流时谈到了mysql跟PG之间在多表关联查询上的一些区别,相比之下mysql只有一种表连接类型:嵌套循环连接(nested-loop),不支持排序-合并连接(sort ...
随机推荐
- parted命令分区
http://soft.chinabyte.com/os/447/12439447.shtml http://blog.163.com/warking_xp/blog/static/103910320 ...
- 牛逼的bootcss之buttons
css源码 /*! @license * * Buttons * Copyright 2012-2014 Alex Wolfe and Rob Levin * * Licensed under the ...
- Curling 2.0(dfs)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8795 Accepted: 3692 Description On Pl ...
- -_-#【jQuery插件】textSlider 文本滚动
jQuery.textSlider.js ;(function($) { $.fn.textSlider = function(settings) { settings = jQuery.extend ...
- weblogic启动报错之建域时未指定AdminServer的监听IP的引起的子节点启动故障
各子节点不能启动,查看日志,报错如下: Unable to establish JMX Connectivity with the Adminstration Server AdminServer a ...
- 【转】Any way to implement BLE notifications in Android-L preview----不错
原文网址:http://stackoverflow.com/questions/24865120/any-way-to-implement-ble-notifications-in-android-l ...
- 图论(KM算法,脑洞题):HNOI 2014 画框(frame)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABPoAAANFCAIAAABtIwXVAAAgAElEQVR4nOydeVxTV/r/n9ertaJEC4
- WebBrowser控件默认使用IE9,IE10的方法
1,打开注册表 HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) SOFTWARE Microsoft Internet E ...
- cf702C Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- UVa11419 SAM I AM(构造最小点覆盖)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27475 [思路] 二分图的最小点覆盖以及构造最小覆盖. 二分图的最 ...