SQL 2 个值共享共同字符的条件
SQL condition where 2 values share common character
我正在尝试创建一个列出 staffID、staffName 和 staffDOB 的查询,但仅限名字和姓氏以相同字母开头的员工。所以我将 staffFirst 和 staffLast 作为单独的列,将它们连接在一起。我不会自定义 staffID 和 staffDOB。我想 return 工作人员的名字,比如 adam apple = a apple,所以输出看起来像:
staffID | staffName | staffDOB
------------------------------
1 | A Apple | 12/10/99
.... | .... | ....
所有列都在同一个 table "N_Staff" 中。我正在使用 HeidiSQL,我相信它使用 MySQL。我知道如何获取每一列的数据,尽管它是选择名字和姓氏的首字母并比较它们,这让我感到困惑,因为它不是我要查找的特定字母,而是两者通用的任何字母table 索引 [0]。
到目前为止:
SELECT staffID FROM N_Staff,
SELECT staffFirst, staffLast AS staffName
FROM N_Staff WHERE ... , --perhaps should be using LEFT ?
SELECT staffDOB from N_Staff;
怎么样:
SELECT staffID, CONCAT(LEFT(staffFirst,1), ' ', staffLast) AS staffName, staffDOB
FROM N_Staff
WHERE LEFT(staffFirst,1) = LEFT(staffLast,1)
使用这个:
SELECT * FROM NS_WORDS;
mani
nikhil
sugandh
mining
_lkdnsad
_lkdndsadnjas
_lk
_ja
_ls
_lsa
nikhil nikhil
nikhil name
SELECT * FROM NS_WORDS
where not( to_char(SUBSTR(a,1,1))=to_char(substr(a,instr(a,' ',1,1),1)));
output:
nikhil nikhil
nikhil name
你会去哪里:
where not( to_char(SUBSTR(staffName ,1,1))=to_char(substr(staffName
,instr(staffName ,' ',1,1),1)));
我正在尝试创建一个列出 staffID、staffName 和 staffDOB 的查询,但仅限名字和姓氏以相同字母开头的员工。所以我将 staffFirst 和 staffLast 作为单独的列,将它们连接在一起。我不会自定义 staffID 和 staffDOB。我想 return 工作人员的名字,比如 adam apple = a apple,所以输出看起来像:
staffID | staffName | staffDOB
------------------------------
1 | A Apple | 12/10/99
.... | .... | ....
所有列都在同一个 table "N_Staff" 中。我正在使用 HeidiSQL,我相信它使用 MySQL。我知道如何获取每一列的数据,尽管它是选择名字和姓氏的首字母并比较它们,这让我感到困惑,因为它不是我要查找的特定字母,而是两者通用的任何字母table 索引 [0]。
到目前为止:
SELECT staffID FROM N_Staff,
SELECT staffFirst, staffLast AS staffName
FROM N_Staff WHERE ... , --perhaps should be using LEFT ?
SELECT staffDOB from N_Staff;
怎么样:
SELECT staffID, CONCAT(LEFT(staffFirst,1), ' ', staffLast) AS staffName, staffDOB
FROM N_Staff
WHERE LEFT(staffFirst,1) = LEFT(staffLast,1)
使用这个:
SELECT * FROM NS_WORDS;
mani
nikhil
sugandh
mining
_lkdnsad
_lkdndsadnjas
_lk
_ja
_ls
_lsa
nikhil nikhil
nikhil name
SELECT * FROM NS_WORDS
where not( to_char(SUBSTR(a,1,1))=to_char(substr(a,instr(a,' ',1,1),1)));
output:
nikhil nikhil
nikhil name
你会去哪里:
where not( to_char(SUBSTR(staffName ,1,1))=to_char(substr(staffName
,instr(staffName ,' ',1,1),1)));