• 主页
• 基础类
• 应用实例
• 新技术前沿

求1条SQL语句 不知道哪出错了

udSoft2020 2007-11-28 09:44:47
SELECT 'A' AS JoinFlag ,A.CODE,B.CODE FROM NameJp AS A
LEFT JOIN (SELECT 'A' AS JoinFlag ,HZ,CODE FROM NameJp) AS B On B.HZ = SUBSTRING('张三',2,1)AND A.JoinFlag=B.JoinFlag
WHERE A.HZ = SUBSTRING('张三',1,1)

...全文
106 点赞 收藏 16

16 条回复

rouqu 2007-11-29

udSoft2020 2007-11-29

rouqu 2007-11-28
SELECT 'A' AS JoinFlag ,A.CODE,B.CODE FROM NameJp AS A
LEFT JOIN (SELECT 'A' AS JoinFlag ,HZ,CODE FROM NameJp) AS B On B.HZ = SUBSTRING('张三',2,1)AND A.JoinFlag=B.JoinFlag
WHERE A.HZ = SUBSTRING('张三',1,1)

-------

select ... from tb1 A left join B on b.x = A.x --问题NameJp中有joinFlag字段吗

--JoinFlag这一列是楼主自定义的没有意义

``````select
[JoinFlag]='A',
A.CODE,
B.CODE
from
NameJp a
left join
NameJp b on 1=1 and  B.HZ='三'--改为1=1..
where
A.HZ='张'``````

-狙击手- 2007-11-28

``````SELECT   'A'   AS   JoinFlag   ,
A.CODE,B.CODE
FROM   NameJp   AS   A
LEFT   JOIN
(SELECT   'A'   AS   JoinFlag   ,
HZ,CODE
FROM   NameJp)   AS   B
On   B.HZ   =   SUBSTRING('张三',2,1)
WHERE   A.HZ   =   SUBSTRING('张三',1,1)``````

stzjzs 2007-11-28

select CONCAT((select code from NameJp where hz = SUBSTRING('张三',1,1)),(select code from NameJp where hz = SUBSTRING('张三',2,1))) as XXX

udSoft2020 2007-11-28

udSoft2020 2007-11-28

``````
select
[JoinFlag]='A',
A.CODE,
B.CODE
from
NameJp a
left join
NameJp b on a.JoinFlag=b.JoinFlag and  B.HZ='三'
where
A.HZ='张'``````

dawugui 2007-11-28
``````--语法没错,就是看不懂这句有啥用?
SELECT 'A' AS JoinFlag , A.CODE , B.CODE
FROM NameJp AS A
LEFT JOIN (SELECT 'A' AS JoinFlag , HZ , CODE FROM NameJp) AS B
On B.HZ = SUBSTRING('张三' , 2 , 1) AND A.JoinFlag = B.JoinFlag
WHERE A.HZ = SUBSTRING('张三',1,1)
``````

udSoft2020 2007-11-28

udSoft2020 2007-11-28
NAMEJP 是一张 姓名的简拼表

CODE 简拼
HZ 汉字

fcuandy 2007-11-28
``````SELECT 'A' AS JoinFlag,A.CODE,B.CODE
FROM NameJp AS A
LEFT JOIN
(SELECT 'A' AS JoinFlag,HZ,CODE
FROM NameJp
) AS B
On B.HZ = SUBSTRING('张三',2,1)
AND A.JoinFlag=B.JoinFlag
WHERE A.HZ = SUBSTRING('张三',1,1)

pt1314917 2007-11-28

MS-SQL Server

3.2w+

MS-SQL Server相关内容讨论专区