简体   繁体   English

SQL缺少表达

[英]SQL Missing Expression

I am trying to select the data where the gender is female or x. 我正在尝试选择性别为女性或x的数据。 It can not be male the code I am using returns Missing Expression : 我使用的代码不能为男性,返回的是Missing Expression:

    SELECT pet_id, name, gender, type, breed
    FROM Pet
    WHERE Name Like '%s' or Name like 'S%'
    And WHERE Gender ='F' or Gender ='X';

Is my formatting okay? 我的格式可以吗?

In your query you have used the where keyword twice which is not valid. 在查询中,您两次使用了where关键字,这是无效的。
The sql syntax prohibits you from doing so, you can have one from and where per select keyword. sql语法禁止您这样做,每个select关键字可以在fromwhere使用一个。
to select multiple fields, you separate by commas. 要选择多个字段,请用逗号分隔。
to select from multiple tables, you separate by commas. 要从多个表中选择,请用逗号分隔。
to use multiple conditions in your where clause you use and & or (this rule applies to most programming languages, you cannot have for example if(x1==1 and if (x2==2)) instead you use if(x1==1 && x2==2) ) 要在使用andor where子句中使用多个条件(此规则适用于大多数编程语言,例如,不能具有if(x1==1 and if (x2==2))而应使用if(x1==1 && x2==2)
also try using the in operator for your condition on gender, as such 还要尝试使用in运算符来确定您的性别状况,例如

Gender in('F','X')

the in operator allows you to check if the value of a given column exists in an array/list/series of possible values. in运算符允许您检查给定列的值是否存在于数组/列表/一系列可能的值中。

You have duplicated "where" in your query. 您在查询中重复了“ where”。 Rewrite in following way should work: 以下列方式重写应该可以工作:

SELECT pet_id, name, gender, type, breed
FROM Pet
WHERE (Name Like '%s' or Name like 'S%') AND (Gender ='F' or Gender ='X');

Try this 尝试这个

SELECT pet_id,name,gender,type,breed FROM Pet
Where (Name Like '%s' or Name like 'S%')
And (Gender ='F' or Gender ='X');

We can't use 'Where' multiple times in single query and as i see in your case you should apply round brackets. 我们不能在单个查询中多次使用“哪里”,并且正如您看到的那样,您应该使用方括号。

Remove second WHERE and don't forget brackets: 移开第二个WHERE,不要忘记括号:

SELECT pet_id, name, gender, type, breed
    FROM Pet
    WHERE (Name Like '%s' or Name like 'S%')
       And Gender in ('F','X')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM