Hello
I have a SQL statement in which I am required to use a HAVING because it has subqueries.
The sentence works correctly for me in MySql but in the grid I get an error:
An error occurred while accessing the database Unknown columna ‘Fecha’ in ‘having clause’
select count(*) from cot_students having Fecha=‘1’
Can you help me?
Thanks
Where are the subqueries requiring HAVING? The way you have it now it is a very straightforward WHERE as in select count(*) from cot_students where Fecha =1
Technically having will substitute for WHERE if you don’t have a group clause, it’s just a bit awkward to me. What is the rest of the select?
Ask ChatGPT… it will solve it for you…
Good afternoon, thanks for the answer.
The sentence is something like this:
SELECT some_fields,
SELECT IF( EXISTS(…), 1, 0) AS Fecha1,
SELECT IF( EXISTS(…), 1, 0) AS Fecha2,
SELECT IF( EXISTS(…), 1, 0) AS Fecha3
FROM my_table
HAVING Fecha1=0 OR Fecha2=1 OR Fecha3=1;
The querys SELECT IF( EXISTS(…), 1, 0) AS xxx are not allways the same.
I’ll try with WHERE instead of HAVING buy I have error in MySql Workbench and Scriptcase (Unknow column Fecha1, 2,3…)
If I use HAVING the error is only in Scriptcase, but not in Workbench
I hope I could explain
Thanks
I find one solution:
SELECT some_fields,
SELECT IF( EXISTS(…), 1, 0) AS Fecha1,
SELECT IF( EXISTS(…), 1, 0) AS Fecha2,
SELECT IF( EXISTS(…), 1, 0) AS Fecha3
FROM my_table
WHERE
SELECT IF( EXISTS(…), 1, 0)=1 OR
SELECT IF( EXISTS(…), 1, 0)=1 OR
SELECT IF( EXISTS(…), 1, 0)=1;
Large but Works,
Thanks…