我需要幫助在4個表上構建VIEW。該視圖應包含以下列:創建Mysql視圖以從不同表中選擇顏色
ER.ID,ER.EMPID,ER.CUSTID,ER.STATUS,ER.DATEREPORTED,ER.REPORT,EB.NAME,CR.CUSTNAME,CR.LOCID,CL。 LOCNAME,DI.DEPTNAME
的別名是:
EMP_REPORT ER,EMP_BIO EB,CUST_RECORD CR,CUST_LOC CL,DEPT_ID DI
的數據模型:
describe EMP_REPORT;
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| empid | int(11) | NO | | NULL | |
| custid | int(11) | NO | | NULL | |
| status | varchar(32) | NO | | NULL | |
| datereported | bigint(20) | NO | | NULL | |
| report | text | YES | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
describe EMP_BIO;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| empid | int(11) | NO | PRI | NULL | |
| name | varchar(56) | NO | | NULL | |
| sex | char(1) | NO | | NULL | |
| deptid | int(11) | NO | | NULL | |
| email | varchar(32) | NO | | NULL | |
| mobile | bigint(20) | YES | | NULL | |
| gtlk | varchar(32) | YES | | NULL | |
| skype | varchar(32) | YES | | NULL | |
| cvid | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
describe CUST_RECORD;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| custid | int(11) | NO | PRI | NULL | auto_increment |
| custname | varchar(32) | NO | | NULL | |
| address | varchar(255) | YES | | NULL | |
| contactp | varchar(32) | YES | | NULL | |
| mobile | bigint(20) | YES | | NULL | |
| locid | int(11) | NO | | NULL | |
| remarks | text | YES | | NULL | |
| date | int(11) | YES | | NULL | |
| addedby | int(11) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
describe CUST_LOC;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| locid | int(11) | NO | PRI | 0 | |
| locname | varchar(32) | NO | | NULL | |
+---------+-------------+------+-----+---------+-------+
describe DEPT_ID;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| deptid | int(11) | NO | | NULL | |
| deptname | varchar(32) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
表EMP_REPORT包含員工提交的報告,需要提取其中的所有顏色。該表中的empid應該用於在EMP_BIO(員工biodata)表中獲取相應的名稱。應使用EMP_REPORT中的custid來獲取CUST_RECORD(客戶記錄)中用於在CUST_LOC(客戶位置)表中獲取locname的相應位置。 EMP_REPORT中的empid用於在EMP_BIO表中獲取相應的deptid,然後用它從DEPT_ID(department id)表中獲取相應的deptname。
我嘗試使用不同的選擇查詢的聯合來構建視圖,但沒有得到正確的結果。請幫幫我。
這是一個更好的版本.. http://pastebin.com/Pkmzamag :) – blacktooth 2010-05-01 16:42:57