本文介紹了如何使用 MySQL SELECT 創建虛擬列?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如果我做 SELECT a AS b 并且 b 不是表中的列,查詢會創建虛擬"列嗎?
If I do SELECT a AS b and b is not a column in the table, would query create the "virtual" column?
事實上,我需要將一些虛擬列合并到查詢中,并將一些信息處理到查詢中,以便我以后可以將其用于每個項目.
in fact, I need to incorporate some virtual column into the query and process some information into the query so I can use it with each item later on.
推薦答案
類似:
SELECT id, email, IF(active = 1, 'enabled', 'disabled') AS account_status FROM users
這允許您進行操作并將其顯示為列.
This allows you to make operations and show it as columns.
您還可以使用連接并將操作顯示為列:
you can also use joins and show operations as columns:
SELECT u.id, e.email, IF(c.id IS NULL, 'no selected', c.name) AS country
FROM users u LEFT JOIN countries c ON u.country_id = c.id
這篇關于如何使用 MySQL SELECT 創建虛擬列?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!