案件情况不起作用

时间:2014-12-09 05:09:51

标签: mysql doctrine dql

我需要什么:

  • 我需要检查eventvisitor.published是否为1然后递增为零,否则eventvisitor等于0。

mysql查询

            SUM(
            CASE
            WHEN eventvisitor.published =1
            THEN eventvisitor.published=eventvisitor.published+0 
            ELSE eventvisitor.published=0
            END
            ) AS eventvsisitorpublished

sql查询工作

$qb->select('
    eve.id,
    SUBSTRING(ed.value,1,150) des,
    eve.membership,
    eve.name,
    eve.abbrName abbr_name,
    eve.membership paid,
    eve.wrapper event_wrapper,
    (case  when attach.cdnUrl is null then attach.value else attach.cdnUrl end) event_samll_wrapper,
    eve.url event_url,
    eve.website,
    eve.eventType,
    venue.name venue_name,
    e.startDate,
    e.endDate,
    ct.name city,
    c.name country,
    c.url country_url,
    c.shortname country_shortname,
    category.id industry_id,
    category.name industry_name,
    category.url industry_url,
    eve.status event_status,
    count(distinct eventvisitor.user) PeopleAttending
')
->add('from', $from);
->innerJoin('Entities\City','ct','with','eve.city = ct.id')
->innerJoin('Entities\Country','c','with','eve.country = c.id')
->innerJoin('Entities\EventEdition','e','with','eve.eventEdition = e.id')
->innerjoin('Entities\EventCategory','cat','with','e.event = cat.event')
->innerjoin('Entities\Category','category','with','cat.category = category.id')
->leftJoin('Entities\Venue','venue','with','e.venue=venue.id')
->leftJoin('Entities\EventVisitor','eventvisitor','with','eve.id=eventvisitor.event')   
//->leftJoin('Entities\Venue','v','with','v.id = e.venue')
->leftJoin('Entities\EventData','ed','with','eve.eventEdition = ed.eventEdition')
->leftJoin('Entities\Attachment','attach','with','eve.wrapperSmall = attach.id')
->Where("ed.title ='desc' or ed.title is null")
->andWhere("eve.id in (".$res.")")
->andWhere("eventvisitor.published =1")
  • 工作检查条件。

我面临的问题:我收到500内部错误

  • 我做错了任何建议都是最受欢迎的。

1 个答案:

答案 0 :(得分:0)

使用此

           SUM(
           IF(eventvisitor.published ==1, eventvisitor.published , 0)
            ) AS eventvsisitorpublished