在查询中选择一个特定的数字作为列值 [英] selecting a specific number as column value in the query
本文介绍了在查询中选择一个特定的数字作为列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这很容易,但是我无法通过搜索找到答案
i think its pretty easy but i couldn't find the answer with searching
我想做这样的事情
if(!$user_logged)
{
$q = "select `id` , 0 as choice from tbl1";
}
else
{
$q = "select tbl1.id , tbl2.choice as choice from tbl1 join tbl2 ON .... ";
}
如果用户未登录,我想选择0作为选择,因此我不需要进行额外的连接 但我明白了
i want to select 0 as the choice if user is not logged so i wouldn't need to do the extra join but i get
Unknown column '0' in 'field list'
推荐答案
尝试以下查询:-
SELECT id,'0' AS Choices FROM tbl1 ;
这篇关于在查询中选择一个特定的数字作为列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文