react & node app, Endpoint looks like this =>
app.get("/query", (req, res) => {
con.query(
`SELECT (${req.query.filter}),
count("${req.query.filter}") AS count,
AVG(age) AS averageAge
from census_learn_sql
GROUP BY (${req.query.filter})
LIMIT ${req.query.limit}`,
(err, result, fields) => {
err ? err : res.send(result);
}
);
});
when req.query.filter is a string without spaces, like 'education'... this works. When I try and find a column name that has spaces such as 'this has spaces' this query doesn't work. How can I fix this?