在使用MySQL进行一些操作时,一开始想不到,就通过问其他人,查询资料而知道的答案。在此分享给大家
用户名根据中午首字母排序
如果数据库使用的是GBK编码,可以直接进行排序
select * from t_user_info order by name
如果使用的是UTF-8编码,则进行转码
select * from t_user_info order by CONVERT(name using gbk) asc
左外连接查询无法匹配的数据
SELECT
*
FROM
t_user_info_test a
LEFT JOIN t_user_info_test b ON a.USER_SOURCE_ID = b.USER_SOURCE_ID
-- 右表的条件放置到 on 的后面,左表的条件放到 on 后面无效(不知道为什么)
AND b.`STATUS` = 'ON_JOB'
AND b.SERVICE_ID = 'S00000012'
WHERE
b.id IS NULL
AND a.`STATUS` = 'ON_JOB'
AND a.SERVICE_ID = 'S00000001';
复制表结构及数据
-- 创建表结构
create table t_user_info_copy like t_user_info;
-- 拷贝数据
insert into t_user_info_copy select * from t_user_info;