Mysql 选择在此位置无效(
我已经用CASE编写了一个查询,但是我遇到了()问题Mysql 选择在此位置无效(,mysql,sql-server,Mysql,Sql Server,我已经用CASE编写了一个查询,但是我遇到了()问题 select SM.subscriber_name as name , SM.accountType as accountType, SM.middlename as middleName, SM.lastname as lastName, SM.title as title, SM.email as email, SM.company as company,
select SM.subscriber_name as name ,
SM.accountType as accountType,
SM.middlename as middleName,
SM.lastname as lastName,
SM.title as title,
SM.email as email,
SM.company as company,
SM.email1 as aEmail,
,
SM.zipcode as zipcode,
SM.phone_no as phoneNumber,
SM.landlinenumber as landlineNumber,
SM.login_id as loginId,
SD.subscriberType as subscriptionType,
SD.product_id as productType,
case SM.state when 'null' then '' as state else STDD.state_name as state end,
case SM.city when 'null' then '' as city else CDD.city_name as city end,
case SM.country when 'null' then '' as country else CD.country_name as country end,
SD.fulldownloadaccess as fullDownloadAccess,
SD.emailid_limit as emailLimit,
SD.acessTime as planTime
from subscriber_master SM ,
subsciber_details SD,
city_details CDD,
state_details STDD,
country_details CD
where SM.subscriber_id=16704 and
SM.subscriber_id=SD.subscriber_id and
SM.country = CD.country_id and
SM.state = STDD.state_id and
SM.city = CDD.city_id;
请帮助我将括号放在哪里。您的查询有几个问题。首先,您的
CASE
表达式写得不正确,表达式必须在任何AS
部分(参见)之前完成,例如
case SM.state when 'null' then '' as state else STDD.state_name as state end,
应写为
case SM.state when 'null' then '' else STDD.state_name end as state,
此外,如果要检查NULL
值,而不是字符串值'NULL'
,则需要将大小写为:
case when SM.state IS NULL then '' else STDD.state_name end as state
另外,您还有一个额外的,
(介于SM.email1作为aEmail,
和SM.zipcode作为zipcode,
)之间
但是,这些问题都不会在标题中显示消息,是否有一些代码没有显示给我们?我想说,您有兴趣将空值显示为空值,因此,您需要重新生成查询,如下所示:
CASE sm.state
WHEN 'null' THEN '' AS state
ELSE stdd.state_name AS state
end,
改写为:
CASE
WHEN sm.state IS NULL THEN ''
ELSE stdd.state_name END AS state,
所有“NULL”都是一样的。另外,AS应该在案例结束后写入
回顾:刚刚意识到下面的句子应该返回相同的内容,但更简洁易读:
ISNULL(sm.state, '') AS state,
您可以更改如下所示的case
语句,它将同时检查null
和空白值
case ISNULL(SM.[state],'') when '' then '' else STDD.state_name end as [state],
case ISNULL(SM.city,'') when '' then '' else CDD.city_name end as city,
case ISNULL(SM.country,'') when '' then '' else CD.country_name end as country
您应该使用join
来提供select语句中不同表之间的where条件。或者,您也可以使用下面修改的查询
select SM.subscriber_name as name ,
SM.accountType as accountType,
SM.middlename as middleName,
SM.lastname as lastName,
SM.title as title,
SM.email as email,
SM.company as company,
SM.email1 as aEmail,
SM.zipcode as zipcode,
SM.phone_no as phoneNumber,
SM.landlinenumber as landlineNumber,
SM.login_id as loginId,
SD.subscriberType as subscriptionType,
SD.product_id as productType,
case ISNULL(SM.[state],'') when '' then '' else STDD.state_name end as [state],
case ISNULL(SM.city,'') when '' then '' else CDD.city_name end as city,
case ISNULL(SM.country,'') when '' then '' else CD.country_name end as country,
SD.fulldownloadaccess as fullDownloadAccess,
SD.emailid_limit as emailLimit,
SD.acessTime as planTime
from subscriber_master SM,
subsciber_details SD,
city_details CDD,
state_details STDD,
country_details CD
where SM.subscriber_id=16704
and SM.subscriber_id=SD.subscriber_id and
SM.country = CD.country_id and
SM.[state] = STDD.state_id and
SM.city = CDD.city_id;
您使用的是哪个数据库?可能是检查语法-->SM.email1作为aEmail
在这两个,
之后。谢谢。您的回答很有帮助