gpt4 book ai didi

php - mySql 未知列

转载 作者:行者123 更新时间:2023-11-29 04:14:19 25 4
gpt4 key购买 nike

我有以下查询

    SELECT 
s.name,
s.surname,
s.id_nr,
s.student_nr,
s.createdate,
s.enddate,
(SELECT count(*) FROM Student_Attendance WHERE absent = 1) AS count_absent
FROM
Student AS s,
Student_Contact AS sc,
Student_Payment AS p,
Student_Courses AS scou,
Modules AS m,
Student_Certificate AS scer,
Student_Results AS sr,
Lecturer_Profile AS l,
Lecturer_Comments AS lc,
Student_Attendance AS sa,
Student_Training AS t
WHERE s.s_id = sc.s_id
AND s.s_id = p.s_id
AND s.s_id = scou.s_id
AND scou.c_id = m.c_id
AND s.s_id = scer.s_id
AND s.s_id = sr.s_id
AND s.s_id = lc.s_id
AND lc.l_id = l.l_id
AND s.s_id = sa.s_id
AND LOWER(s.name) = 'andile'
AND LOWER(s.surname) = ' orson vulture'
AND s.id_nr = 8403125062671
AND LOWER(sc.race) = 'white'
AND sc.gender = 1
AND LOWER(sc.area) = 'gauteng'
AND p.payment_type = 1
AND s.student_nr = 203087506
AND scou.c_id = 1 AND sc.age = 23
AND scer.certificate_number = 3424234
AND sr.result = 32
AND l.l_id= 1
AND count_absent = 3
AND LOWER(s.branch) = 'pretoria'
AND LOWER(s.campus_name) = 'pretoria'
AND LOWER(sc.kin_name) = 'self'
AND t.s_id = s.s_id
AND t.sp_id = 1

我得到以下错误

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count_absent' in 'where clause'

不知道如何解决这个问题,因为该列在 select 语句中

最佳答案

您的派生列 count_absent 在 SELECT 子句中处理,该子句在 WHERE 子句之后处理,因此不可用。如果您将整个查询包装在外部 SELECT 中,以便能够访问派生列,它将可用。

select * from (
SELECT
s.name,
s.surname,
s.id_nr,
s.student_nr,
s.createdate,
s.enddate,
(SELECT count(*) FROM Student_Attendance WHERE absent = 1) AS count_absent
FROM
Student AS s,
Student_Contact AS sc,
Student_Payment AS p,
Student_Courses AS scou,
Modules AS m,
Student_Certificate AS scer,
Student_Results AS sr,
Lecturer_Profile AS l,
Lecturer_Comments AS lc,
Student_Attendance AS sa,
Student_Training AS t
WHERE s.s_id = sc.s_id
AND s.s_id = p.s_id
...
AND t.s_id = s.s_id
AND t.sp_id = 1
) as x where count_absent = 3

关于php - mySql 未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1625686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com