我需要什么
这是我的查询语法
此语法中的问题请指出我的错误。
(case
when user.linkedinProfile IS NOT NULL or user.country=$country_code
then 1
else
case
when user.profile IS NOT NULL or user.country=$country_code
THEN 2
else
end
case
when user.country or user.country=$country_code
then 3
else 4
end
END)as country
我做错了(我使用过case - > when->然后 - > else-> end)。
但是sql查询在数据库中工作:
SELECT e0_.metadata AS metadata0, u1_.id AS id1, u1_.linkedin_id AS linkedin_id2, u1_.facebook_id AS facebook_id3, u1_.linkedin_profile AS linkedin_profile4, u1_.profile AS
profile5,u1_.country,
CASE WHEN u1_.linkedin_id <> '' OR u1_.facebook_id <> '' THEN 1 ELSE 0 END AS sclr6,
CASE WHEN e0_.edition = 23932 THEN 'current' ELSE 'past' END AS sclr7 ,
case
when u1_.linkedin_profile!='' and u1_.country='IN'
then '1'
when u1_.profile!='' and u1_.country='IN'
then '2'
when u1_.country and u1_.country='IN'
then '3'
else '4'
END lower
FROM event_visitor e0_, user u1_
WHERE e0_.user = u1_.id AND e0_.event = 25162 AND e0_.published = 1 GROUP BY
e0_.user ORDER BY e0_.edition DESC, sclr6 DESC, e0_.id DESC , u1_.country DESC LIMIT 30 OFFSET 0
我优先考虑查询。
我已从Nested CASE statements in MySQL
获得帮助喜欢前
linkedln url (not null) and country ( 1 priority).
profile (not null) and country (2 priority).
country (not null) and country( 3 priority).
我找到了解决方案:
(case
when (user.linkedinProfile !='' or user.profile !='') and user.country= '$country_code'
then 1
when
user.linkedinProfile<>'' or user.profile!=''
then 2
when user.country='$country_code'
then 3
else 4 end) country
错误:
PHP Fatal error: Uncaught exception 'Doctrine\\ORM\\Query\\QueryException' with message 'SELECT user.country,visitor.metadata,user.id user_id,user.linkedinId,user.facebookId,user.linkedinProfile,user.profile,\n\t\t\t\t(case when user.linkedinId !='' or user.facebookId !='' then 1 else 0 end) social,\n\t\t\t\t(case when visitor.edition =23932 then 'current' else 'past' end) edition,\n\t\t\t\t\n\t\t\t\tCASE\n\t\t\t\t WHEN (user.linkedin_profile IS NOT NULL and user.country='IN' )\n\t\t\t\tTHEN \n\t\t\t\tCASE\n\t\t\t\t WHEN(user.profile IS NOT NULL and user.country='IN')\n\t\t\t\tTHEN '2' \n\t\t\t ELSE '3' \n\t\t\t\tEND\n\t\t\t\tELSE\n\t\t\t\tCASE\n\t\t\t\t WHEN (user.country and user.country='IN')\n\t\t\t\tTHEN '4'\n\t\t\t\tELSE '5'\n\t\t\t\tEND\n\t\t\t\tEND AS product_total\n\t\t\t\t FROM Entities\\EventVisitor visitor,Entities\\User user WHERE visitor.user=user.id AND visitor.event=25162 AND visitor.published=1 GROUP BY visitor.user ORDER BY visitor.edition desc, social desc, visitor.id desc' in /home/indiamart/public_html/serve-biztradeshows-com/application/libraries/Doctrine/ORM/Query/QueryExce in /home/indiamart/public_html/serve-biztradeshows-com/application/libraries/Doctrine/ORM/Query/QueryException.php on line 44