SQL查询以检索特定的名字

/ 10。编写一个SQL查询以检索处于CA,TX,FL,NV,NM状态的贷款的贷款号,州和城市,客户的名字 但不包括以下城市(达拉斯,旧金山和奥克兰),并且仅退还客户名字以约翰开头的贷款。/

我尝试了什么:

SELECT [LoanNumber],[State],[City],[CustomerFname]
FROM dbo.Loan
WHERE STATE IN( 'CA','TX','FL','NV','NM') 
AND CITY NOT IN('DALLAS','SANFRANCISCO','OAKLAND')
HAVING [CustomerFname]=' Mr.John'
评论
  • bsequi
    bsequi 回复
    SELECT [LoanNumber],[State],[City],[CustomerFname]
        FROM dbo.Loan
        WHERE STATE IN( 'CA','TX','FL','NV','NM') 
        AND CITY NOT IN('DALLAS','SANFRANCISCO','OAKLAND')
        AND [CustomerFname] LIKE '%Mr.John%'
    
  • 你带走了爱
    你带走了爱 回复

    仅在字符串末尾添加通配符条目(%),以使客户从John开始。

    SELECT [LoanNumber],[State],[City],[CustomerFname]
        FROM dbo.Loan
        WHERE STATE IN( 'CA','TX','FL','NV','NM') 
        AND CITY NOT IN('DALLAS','SANFRANCISCO','OAKLAND')
        AND [CustomerFname] LIKE 'Mr.John%'