Discussion:
資料連結問題
(时间太久无法回复)
jimmy
2007-03-08 04:30:03 UTC
Permalink
/* INVMB table的 MB001欄位資料 MB006欄位資料 MB007欄位資料
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002

INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD

如果要將MB006、MB007 JOIN MA002並顯示結果為

MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL

以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^
David
2007-03-08 07:23:03 UTC
Permalink
SELECT A.MB001,A.MB006,B.MA003,A.MB007,B1.MA003 as MA0031
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
LEFT JOIN INVMA AS B1 ON A.MB007 = B1.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001

連結部份要下兩次才行,請參考看看!

"jimmy" 來函:
Post by jimmy
/* INVMB table的 MB001欄位資料 MB006欄位資料 MB007欄位資料
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002
INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD
如果要將MB006、MB007 JOIN MA002並顯示結果為
MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL
以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^
jimmy
2007-03-08 09:27:13 UTC
Permalink
謝謝您的解答,想在請問
B1.MA003 AS MA003
為何要這樣寫?
如果再加一個連結A.MB008 =B.MA002,變成多連結一次,如何使用
--
jimmy-hsieh


"David" 來函:
Post by David
SELECT A.MB001,A.MB006,B.MA003,A.MB007,B1.MA003 as MA0031
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
LEFT JOIN INVMA AS B1 ON A.MB007 = B1.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結部份要下兩次才行,請參考看看!
"jimmy" 來函:
Post by jimmy
/* INVMB table的 MB001欄位資料 MB006欄位資料 MB007欄位資料
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002
INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD
如果要將MB006、MB007 JOIN MA002並顯示結果為
MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL
以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^
jimmy
2007-03-08 09:51:25 UTC
Permalink
再次詢問的問題,已經了解,再次感謝您的幫忙
--
jimmy-hsieh


"jimmy" 來函:
Post by jimmy
謝謝您的解答,想在請問
B1.MA003 AS MA003
為何要這樣寫?
如果再加一個連結A.MB008 =B.MA002,變成多連結一次,如何使用
--
jimmy-hsieh
"David" 來函:
Post by David
SELECT A.MB001,A.MB006,B.MA003,A.MB007,B1.MA003 as MA0031
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
LEFT JOIN INVMA AS B1 ON A.MB007 = B1.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結部份要下兩次才行,請參考看看!
"jimmy" 來函:
Post by jimmy
/* INVMB table的 MB001欄位資料 MB006欄位資料 MB007欄位資料
SK1070-ACD90 2001
3001
SK1070-ACD90-3 2002
3002
INVMA table的 MA002欄位資料 MA003欄位資料
2001 AA
2002 BB
3001 CC
3002 DD
如果要將MB006、MB007 JOIN MA002並顯示結果為
MB001 MB006 MA003 MB007
MA003
SK1070-ACD90 2001 AA 3001
CC
SK1070-ACD90-3 2002 BB 3002
DD
請問如使用下SQL
以下是我寫的語法
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
連結一個欄位沒問題,如果是連結兩個欄位會變成MA003欄位變成空值,語法如下
SELECT
A.MB001,A.MB002,A.MB003,A.MB004,A.MB005,A.MB006,A.MB007,A.MB008,A.MB009,
B.MA003
FROM INVMB AS A LEFT JOIN INVMA AS B ON A.MB006 = B.MA002 AND A.MB007 =
B.MA003
WHERE A.MB001 LIKE 'SK%'
ORDER BY A.MB001
問題出在哪邊,幫忙解答一下吧 ^.^
Loading...