码迷,mamicode.com
首页 > 数据库 > 详细

常用sql语句

时间:2019-01-03 10:54:13      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:cto   --   where   常用sql   end   null   ||   style   directory   

1.模糊匹配,b表记录不在a表中的

select b.name,a.zymc from a
   left join b
on instr(b.name,a.zymc) >0
where b.name is null

2.根据主副id拼出目录

select c.id_directory_parent,  -- c表副id
         c.id_directory, -- c表主id
         b.id_directory, -- b表主id
         a.id_directory, -- a表主id
case when b.id_directory_parent is null then / || a.directory_name
        when c.id_directory_parent is null then / || b.directory_name || / ||a.directory_name
       else / || c.directory_name || / || b.directory_name  || / || a.directory_name  end as ml
from r_directory a
left join r_directory b
on a.id_directory_parent = b.id_directory
left join r_directory  c
on b.id_directory_parent  = c.id_directory

常用sql语句

标签:cto   --   where   常用sql   end   null   ||   style   directory   

原文地址:https://www.cnblogs.com/tomatoes-/p/10212480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!