Answer the question
In order to leave comments, you need to log in
How to insert aggregate function Max and sort descending?
Guys good afternoon.
I make a request to get the number of 'no' from the new_1answers table for each question recorded in the new_question table . At the same time, it is not possible to implement a descending grouping and how to display a question with the maximum value (everywhere aggregate functions are given only in simple examples).
SELECT COUNT(a), q.title
FROM new_1answers a
JOIN new_question q
ON a.id_question = q.id_question
WHERE a.a = 'no'
group by q.title
create table new_1answers
(
id_report integer
constraint new_1answers_id_report_fkey
references new_1report,
a varchar(8),
id_question integer
);
create table new_question
(
id_question serial not null,
title text
);
Answer the question
In order to leave comments, you need to log in
SELECT COUNT(a), q.title
FROM new_1answers a
JOIN new_question q
ON a.id_question = q.id_question
WHERE a.a = 'no'
group by q.title
order by 1 desc limit 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question