mysql常用sql语句

MySQL 关联表批量修改(数据同步)

因为在代码中新建分配记录数据时忘记加入资源id。发现后,从操作记录表中获取对应的资源id,批量修改。

 

 

update xd_resource_distribution xdrd, xd_resource_operation xdro set xdrd.resources_id = xdro.resources_id where xdro.operation_records
like '分配了%' and xdrd.dis_time = xdro.operating_time;

 

 

 

MySQL判断是否有符合条件的数据

select 1 from tableName where col  = 'col' limit 1;

 

MySQL 字符串拼接

CONCAT(string1,string2,…)   说明 : string1,string2代表字符串,concat函数在连接字符串的时候,只要其中一个是NULL,那么将返回NULL

CONCAT_WS(separator,str1,str2,...)
     说明 : string1,string2代表字符串,concat_ws 代表 concat with separator,第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。如果分隔符为 NULL,则结果为 NULL。函数会忽略任何分隔符参数后的 NULL 值。

group_concat(name)

  说明:将多行转化为一行,多用于group by

mysql实现oracle的rownum功能

SELECT @rowno:=@rowno+1 as rowno,r.* from story r ,(select @rowno:=0) t;

 

mysql自定义函数

USE `mytest`;
DROP function IF EXISTS `new_function`;

DELIMITER $$
USE `mytest`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `new_function`() RETURNS text CHARSET utf8mb4
    DETERMINISTIC
BEGIN

declare allNames text default '';
declare oneName varchar(45);

declare student_list cursor for select t.name from cai_student t;

declare continue handler for SQLSTATE '02000' SET oneName = null; 

open student_list;

FETCH student_list INTO oneName;

while oneName is not null do

set allNames = CONCAT(allNames ,oneName,'_') ; 

FETCH student_list INTO oneName;

end while;
close student_list;


RETURN allNames;
END$$

DELIMITER ;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值