Я сделал как подзапрос, как это, но он выдавал ошибку
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' и получил ошибку, подобную этой
Код ошибки: 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'
Может ли кто-нибудь помочь ...