2014-01-21 115 views
2

這是我的原始表格。在Mysql中更改屬性名稱

+----------+---------------------+--------+------------+-------+ 
| lab_code | test_name   | sample | time_taken | price | 
+----------+---------------------+--------+------------+-------+ 
| FBS  | Fasting blood Suagr | Blood | 01:15:00 | 400 | 
| STLC  | Stool Culture  | Stool | 48:00:00 | 700 | 
| UA  | Urinalysis   | Urine | 02:30:00 | 425 | 
| UDS  | Urine drug screen | Urine | 06:00:00 | 550 | 
+----------+---------------------+--------+------------+-------+ 

我想顯示

+----------+ 
| Hospital | 
+----------+ 
| FBS  | 
| STLC  | 
| UA  | 
| UDS  | 
+----------+ 

我想改變attibute名稱時數據Quering。(不改變原始表) plz幫助。

+0

這個詞是列別名 –

+3

這個問題似乎是題外話,因爲它沒有顯示研究成果 – Strawberry

回答

5

ALIAS名特定列

SELECT lab_code AS Hospital 
From tableA 
+0

.........謝謝.......... – 7evenline

+2

@ 7evenline你是最受歡迎的。請參閱http://stackoverflow.com/total上的stackoverflow –

1

嘗試這樣

aliases用於臨時重命名列名(或在其他情況下,表名)

SELECT lab_code AS Hospital FROM Table 
+0

.........謝謝.......... – 7evenline

1
SELECT lab_code AS Hospital 

FROM Original_Table 
+0

.........謝謝... ....... – 7evenline

2

SELECT lab_code AS Hospital FROM <table_name>; 

使用AS是一個ALIAS可以用於列名;這並不意味着該表的列名更改,而是在執行SELECT查詢時,它將成爲表中當前列名的列名或別名。

+0

.........謝謝.......... – 7evenline

+0

@ 7evenline沒問題。 – blackpanther

1

試試這個:

SELECT "lab_code" AS "Hospital" FROM "table"; 
+0

.........謝謝.......... – 7evenline

2

試試這個

SELECT lab_code AS Hospital From original_table 

它將與不AS

SELECT lab_code Hospital From original_table 
+0

.........謝謝.......... – 7evenline

+0

@ 7evenline歡迎您.. – zzlalani

1

工作如果lab_code不是主鍵使用此查詢

SELECT DISTINCT lab_code AS Hospital 
FROM myTable 
+0

.........謝謝.......... – 7evenline