我做喜歡這樣子查詢,但它給錯誤在主查詢中使用子查詢
SELECT
sourceTable3.Total,
(sourcetable3.datediff-1) as diff,
ADDDATE(ADDDATE(NOW(), INTERVAL FLOOR(diff) MONTH), INTERVAL DAY(NOW()) - memberToMship_DueDay DAY) As expdate,
ExpPayments,
MonthlyAmount,
SourceTable3.ExpPayments2,
FROM
(
SELECT
SourceTable2.Total,
(SourceTable2.datdiff-1) as diff,
SourceTable2.datdiff,
ExpPayments,
MonthlyAmount,
SourceTable2.ExpPayments2,
member_Id
FROM
(
SELECT
SourceTable.Total,
ceil(SourceTable.ExpPayments-SourceTable.Total) AS datdiff,
SourceTable.ExpPayments,
SourceTable.MonthlyAmount,
(SourceTable.Total/SourceTable.MonthlyAmount) as ExpPayments2,
SourceTable.member_Id
FROM
(
SELECT TIMESTAMPDIFF(MONTH,memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As Total,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS ExpPayments,
30* memberToMship_ChargePerPeriod/DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS MonthlyAmount,
member_Id
FROM
membertomships
) as SourceTable
) as SourceTable2
) as sourceTable3
但它給錯誤是這樣的...
Error Code: 1054
Unknown column 'sourcetable3.datediff' in 'field list'
會不會有人請幫助。 ..
修改後的代碼:
修改 'e' 和有這樣
012錯誤錯誤代碼:1054在 '字段列表'
修改後的代碼 未知列 'memberTo_Mship_DueDay':
這是我的表結構
membership table
memberToMship_Id
memberToMship_StartDate
memberToMship_EndDate
memberToMship_DueDay
member_Id
I want finally these columns expdate , diff , ExpPayments,
MonthlyAmount,
MODIFIED CODE :
SELECT
SourceTable3.Total,
ADDDATE(ADDDATE(NOW(), INTERVAL FLOOR(diff) MONTH), INTERVAL DAY(NOW()) - memberToMship_DueDay DAY) As expdate,
(Sourcetable3.datdiff-1) as diff,
ExpPayments,
MonthlyAmount,
SourceTable3.ExpPayments2,
SourceTable3.member_Id
FROM
(
SELECT
SourceTable2.Total,
(SourceTable2.datdiff-1) as diff,
SourceTable2.datdiff,
ExpPayments,
MonthlyAmount,
SourceTable2.ExpPayments2,
member_Id
FROM
(
SELECT
SourceTable.Total,
ceil(SourceTable.ExpPayments-SourceTable.Total) AS datdiff,
SourceTable.ExpPayments,
SourceTable.MonthlyAmount,
(SourceTable.Total/SourceTable.MonthlyAmount) as ExpPayments2,
SourceTable.member_Id
FROM
(
SELECT TIMESTAMPDIFF(MONTH,memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As Total,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS ExpPayments,
30* memberToMship_ChargePerPeriod/ DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS MonthlyAmount,
member_Id
FROM
membertomships
) as SourceTable
) as SourceTable2
) as SourceTable3
和錯誤
Error Code: 1054
Unknown column 'memberToMship_DueDay' in 'field list'
任何人會幫助...
拜託,請檢查您的表 – wonk0
@ wonk0我有一個像這些領域中memberTomship表中的列memberTo_Mship_DueDay ... memberToMship_EndDate,memberToMship_StartDate – user682417
@ user682417你仍然有問題,請給你的桌面截圖與你想要的結果。 – rahularyansharma