duannao3402 2013-10-21 17:07
浏览 9

选择即时创建的字段

Assume a table bank contains 3 fields, id, name, and balance.

I am trying to understand how to select all fields from this table and add another custom field to the result set as follows:

Query (something like)

SELECT * FROM bank WHERE balance+10 AS plusTen AND id != 12

PHP

echo $row['plusTen']; //echos whatever balance was for this record + 10 added to it

Is this even possible?

I appreciate any suggestions.

  • 写回答

2条回答 默认 最新

  • duanfu5239 2013-10-21 17:09
    关注
    SELECT *, balance+10 AS plusTen
    FROM ...
    etc...
    

    you can create virtual fields in a WHERE clause, if you insist, but things in where clauses don't get returned to the client, because they simply act as filters. You need to actually create the virtual field in the field portion of the query, as above.

    评论

报告相同问题?