表名 test99
select test99.id ,test99.name,test9.name
from test99,(select * from test99 test where len(test.id)=3) test9
where test9.id = left(test99.id,3) and len(test99.id) = 6
select test99.id ,test99.name,test9.name
from test99,(select * from test99 test where len(test.id)=3) test9
where test9.id = left(test99.id,3) and len(test99.id) = 6
解决方案 »
- 数据库忽然出错:Cannot resolve collation conflict for equal to operation
- 如何自动识别数据库的变化
- 各位大哥,安装SQL server失败,帮我看看啊!
- 发布数据库程序,用 Attach 数据库好,还是 SQL Script 好
- sql去掉重复
- Server2000 安装问题和系统问题
- sql 中怎么抽出数据用另外的表表示出来
- 请教大家一下,sqlserver2000怎样在win98下安装服务器组件
- 两个问题:1.如何lock住一个表 2.如何lock住一个数据库(也就是所有表),都是要能够独占
- 请问各位LinkServer是什么?
- 请指出文章中的错误:论数据库设计和应用设计的关系
- 关于DB--LIBRARY的问题?
FROM dbo.test a INNER JOIN
dbo.test b ON a.id = LEFT(b.id, 3) AND LEN(b.id) > 3
测试通过
id name
001 研发部
001001 设计组
001002 开发组
001003 测试组
002 销售部
002001 调研组
002001 客服组
003 行政部
sql 语句得到结果
001001 研发部\设计组
001002 研发部\开发组
001003 研发部\测试组
002001 销售部\调研组
002001 销售部\客服组
003 行政部我一葫芦画瓢,改造了一下 可是只是得到结果
001001 研发部\设计组
001002 研发部\开发组
001003 研发部\测试组
002001 销售部\调研组
002001 销售部\客服组
003 行政部\行政部
虽可凑或 但不完美,如何搞定?
SELECT b.id, case b.id
when len(b.id)>3 then a.name + b.name
else a.name
end
FROM dbo.test a INNER JOIN
dbo.test b ON a.id = LEFT(b.id, 3)
FROM tablename AS A, tablename AS B
WHERE len(A.id)=3 and len(B.id)=6 and a.id=left(b.id,3);在ACCESS里测试过了,没问题。