我的陈述是否正确
$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'") ;
我尝试了这个,但抛出空的结果。不知道什么是错的
更新
SELECT 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'
答案 0 :(得分: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'") ;