创建表,数据:
create table t(str varchar(100))
insert into t values ('0,1,2,34')
执行:
SELECTgroup_concat(
RIGHT (
concat(
'00',
substring_index(
substring_index(
a.str,
',',
b.help_topic_id + 1
),
',' ,- 1
)
),
3
)
)
FROM
t a
JOIN mysql.help_topic b ON b.help_topic_id < (
length(a.str) - length(REPLACE(a.str, ',', '')) + 1
)
结果:
使用MYSQL -I命令,查看MYSQL命令的参数,其中对--auto-rehash参数的说明如下:--auto-rehash Enable automatic rehashing. One doesn&#39t need to use &#39rehash&#39to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash. 网上也找了一些资料,说是打开MYSQL的自动补全功能,类似于LINUX的TAB键补全功能。但如下使用该参数后,输入SQL命令,中途按TAB健,并未出现自动补全的效果,不知道如何 *** 作: [sql] C:\Users\qxlmysql -u root --auto-rehash Welcome to the MySQL monitor. Commands end with or \g. Your MySQL connection id is 29 Server version: 5.1.28-rc-community MySQL Community Server (GPL) Type &#39help&#39or &#39\h&#39for help. Type &#39\c&#39to clear the buffer. mysql use test Database changed mysql select * from newnam1.近n个月
不废话 直接上sql
SELECT
DATE_FORMAT( @cdate := DATE_ADD( @cdate, INTERVAL - 1 MONTH ), '%Y-%m' ) AS cmonth
FROM
( SELECT @cdate := DATE_ADD( '2020-7-1', INTERVAL + 1 MONTH ) FROM information_schema.CHARACTER_SETS ) t0
LIMIT 100
注意 information_schema.CHARACTER_SETS这个表是mysql系统表,可以取到的最大月数和这个表的数量有关,如果又更多的时间要选,可以查询其他表,数据量不要太大,太大会影响查询效率
2 同理 上近n天
SELECT
@cdate := DATE_ADD( @cdate, INTERVAL - 1 DAY )AS DAYS
FROM
( SELECT @cdate := DATE_ADD( '2020-7-1', INTERVAL + 1 DAY ) FROM information_schema.CHARACTER_SETS ) t0
LIMIT 100
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)