我有如下的表department
用查询语句:
select * from department where code like '001%'
得到如下的表:
ID AREA CODE NAME
1 001 001 可的集团
2 00101 00101 长宁店
3 0010101 0010101 长宁店部门1
4 00102 00102 徐汇店
5 00105 00105 财务部
6 00106 00106 酒店管理部我要得如下的查询列表,参数只有code 传入为"001"的值
有什么语句可以得到上面的3,4,5,6条记录啊?也就是只取子及部门的信息列表!
用查询语句:
select * from department where code like '001%'
得到如下的表:
ID AREA CODE NAME
1 001 001 可的集团
2 00101 00101 长宁店
3 0010101 0010101 长宁店部门1
4 00102 00102 徐汇店
5 00105 00105 财务部
6 00106 00106 酒店管理部我要得如下的查询列表,参数只有code 传入为"001"的值
有什么语句可以得到上面的3,4,5,6条记录啊?也就是只取子及部门的信息列表!
第2条记录要不要呢?不要的话在加条件.
select * from department t2 where code like '001%' and not exists(select 1 from department t1 where t1.code like t2.code||'%' and t1.code<>t2.code)
这个语句在sql中报错,||处有错误!