我可以根据表中的值返回字符串吗?
考虑以下查询:
SELECT 操作,[...] FROM tableName
操作
字段将检索 1 到 4 之间的整数。我想要做的是分配一个基于操作
的整数值,将字符串值赋给 SQL 查询中的变量。
如果由我决定,我将有一个包含每个操作名称的相应表,在这种情况下,JOIN
将拾取操作字符串。不幸的是,我无法控制数据库。
我不知道这是否是 SQL 可以做的事情,我当然可以使用 PHP 迭代返回的数据来执行此任务,但如果可能的话,一次完成所有操作是有意义的。
Consider the following query:
SELECT operation, [...] FROM tableName
The operation
field will retrieve an integer from 1 to 4. What I would like to do is assign a string value to a variable in the SQL query, based on the integer value of operation
.
If it were up to me, I would have a corresponding table that contained the name of each operation, in which case a JOIN
would pick up the operation string. Unfortunately, I do not control the database.
I don't know if this is even something SQL can do, and I could certainly iterate over the returned data using PHP to perform this task instead, but it makes sense to do it all in one hit if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一些方法来消除这个:
Try something kile this: