使用查询的结果进行进一步的计算,这些结果在同一查询中给出错误
我已经这样写了查询 我想用这些结果进一步计算,对于所有单个查询来说,
SELECT TIMESTAMPDIFF(MONTH,memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As totalcontractamountperiod ,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS exppayments,
30* memberToMship_ChargePerPeriod / DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS monthlyamount,
(totalcontractamountperiod/monthlyamount) as exppayments,
member_Id
FROM membertomships;
是否所有的结果都可能使用 mysql 进行单个查询,
但它给出了这样的错误,
Error Code: 1054
Unknown column 'totalcontractamountperiod' in 'field list'
任何人都可以了解这个
修改的代码:我已经通过使用子查询完成了这样的操作....
SELECT
EXPPAYMENT WHERE EXPPAYMENT =(TIMESTAMPDIFF(MONTH, memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As totalcontractamountperiod ,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS exppayments ,
30* memberToMship_ChargePerPeriod / DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS monthlyamount ,
(totalcontractamountperiod/monthlyamount) as exppayments, member_Id
FROM membertomships);
但它给出了这样的错误
Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE EXPPAYMENT =(TIMESTAMPDIFF(MONTH, memberToMship_StartDate,memberToMship_En' at line 1
,这是修改后的查询,并向查询添加了另外两个函数,但它仍然给出了
SELECT
Total,
(datdiff-1) as diff,
ceil(ExpPayments-Total) AS datdiff,
ExpPayments,
MonthlyAmount,
(Total/MonthlyAmount) as ExpPayments2,
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;
这样的错误错误,
Error Code: 1054
Unknown column 'datdiff' in 'field list'
请帮忙
SELECT
SourceTable.Total,
ceil(SourceTable.ExpPayments-SourceTable.Total) AS datdiff,
ceil(SourceTable.ExpPayments-SourceTable.Total) -1 as diff,
ADDDATE(ADDDATE(NOW(), INTERVAL FLOOR(ceil(SourceTable.ExpPayments- SourceTable.Total) -1) MONTH), INTERVAL DAY(NOW()) - SourceTable.memberToMship_DueDay DAY) As expdate,
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
错误代码:1054 “字段列表”中的未知列“SourceTable.memberToMship_DueDay”
i have written the query like this
and i want to caluculate further with these results that to all in single query
SELECT TIMESTAMPDIFF(MONTH,memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As totalcontractamountperiod ,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS exppayments,
30* memberToMship_ChargePerPeriod / DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS monthlyamount,
(totalcontractamountperiod/monthlyamount) as exppayments,
member_Id
FROM membertomships;
is it possible that all comes in single query using mysql
but it was giving error like this
Error Code: 1054
Unknown column 'totalcontractamountperiod' in 'field list'
can anyone have idea about this
MODIFIED CODE : I have done like this by using subqueries....
SELECT
EXPPAYMENT WHERE EXPPAYMENT =(TIMESTAMPDIFF(MONTH, memberToMship_StartDate,memberToMship_EndDate)* memberToMship_ChargePerPeriod As totalcontractamountperiod ,
DATEDIFF(GREATEST(NOW(),memberToMship_DueDay),memberToMship_StartDate)/30 AS exppayments ,
30* memberToMship_ChargePerPeriod / DATEDIFF(memberToMship_EndDate,memberToMship_StartDate) AS monthlyamount ,
(totalcontractamountperiod/monthlyamount) as exppayments, member_Id
FROM membertomships);
but it was giving error like this
Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE EXPPAYMENT =(TIMESTAMPDIFF(MONTH, memberToMship_StartDate,memberToMship_En' at line 1
and this is the modified query and added two more functions to the query but sill it was giving error
SELECT
Total,
(datdiff-1) as diff,
ceil(ExpPayments-Total) AS datdiff,
ExpPayments,
MonthlyAmount,
(Total/MonthlyAmount) as ExpPayments2,
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;
error like this
Error Code: 1054
Unknown column 'datdiff' in 'field list'
would you pls help
SELECT
SourceTable.Total,
ceil(SourceTable.ExpPayments-SourceTable.Total) AS datdiff,
ceil(SourceTable.ExpPayments-SourceTable.Total) -1 as diff,
ADDDATE(ADDDATE(NOW(), INTERVAL FLOOR(ceil(SourceTable.ExpPayments- SourceTable.Total) -1) MONTH), INTERVAL DAY(NOW()) - SourceTable.memberToMship_DueDay DAY) As expdate,
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
Error Code: 1054
Unknown column 'SourceTable.memberToMship_DueDay' in 'field list'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将缩写一些列名称,因为它们有点长,因此查询可以更清晰:
问题出在指出的行中,因为您正在使用
Total
和 < code>MonthlyAmount 在定义它们的同一列列表中。我知道它看起来应该可以工作,但是这样使用 SQL 是非法的。您可以做的是:
:
:
顺便说一句,原始查询中的两列名为 ExpPayments,我将第二个列重命名为 ExpPayments2。
I'll abreviate some of the column names as they are a bit on the long side, so the query can be more clear:
The problem is in the pointed row, as you are using the
Total
andMonthlyAmount
in the same column list that defines them. I know it look like it should work, but it's illegal to use SQL like that.What you could do is:
this:
this:
BTW, two columns in the original query are named ExpPayments, I renamed the second ExpPayments2.
修改后的代码也有同样的问题。应该是:
You've got the same problem with the modified code. It should be: