0

我的陈述是否正确

$uid=1;
$pby=1;

$db->query("SELECT 
  CASE WHEN (c.uid!='$uid' and c.uid!='$pby')
    THEN
      ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
   comments c join users u on c.uid=u.uid where c.msgid='$id' and 
   c.condition!='ga'   order by c.tstamp desc limit 10)
      )
 ELSE 
     ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
      comments c join users u on c.uid=u.uid where c.msgid='$id'  
      order by c.tstamp desc limit 10)
      )
  END
  FROM comments c where c.msg_id='$id'") ;

我试过了,但结果是空的。不知道怎么了

更新到

选择 c.id、c.comment、c.uid、c.msgid、c.tstamp、u.fullname、u.img

  CASE WHEN (c.uid!='$uid' and c.uid!='$pby')
    THEN
      ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
   comments c join users u on c.uid=u.uid where c.msgid='$id' and 
   c.condition!='ga'   order by c.tstamp desc limit 10)
      )
 ELSE 
     ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
      comments c join users u on c.uid=u.uid where c.msgid='$id'  
      order by c.tstamp desc limit 10)
      )
  END
  FROM comments c join users u on c.uid=u.uid where c.msgid='$id'
4

1 回答 1

0

请指定您要选择的字段并将查询更新为

$db->query("SELECT field1, field2
  CASE WHEN (c.uid!='$uid' and c.uid!='$pby')
    THEN
      ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
   comments c join users u on c.uid=u.uid where c.msgid='$id' and 
   c.condition!='ga'   order by c.tstamp desc limit 10)
      )
 ELSE 
     ( SELECT c.id, c.comment, c.uid,c.msgid, c.tstamp, u.fullname, u.img FROM 
      comments c join users u on c.uid=u.uid where c.msgid='$id'  
      order by c.tstamp desc limit 10)
      )
  END
  FROM comments c where c.msg_id='$id'") ;
于 2013-11-06T07:17:06.263 回答