I have a table, called feedback, that contains: no, date, id, message, value.
noThe row number.idThe employee id.messageFeedback from a customer.valueThe feedback type. -1, 0, or 1.
Now I have a view which provides me with id, messages, total, value.
idThe employee id.messagesAn array ofmessagewhich shareidandvalue.totalThe total number of rows which shareidandvalue.
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `vw_feedback` AS
SELECT
`feedback`.`no` AS `no`,
`feedback`.`id` AS `id`,
JSON_ARRAYAGG(`feedback`.`message`) AS `messages`,
`feedback`.`value` AS `value`,
COUNT(0) AS `total`
FROM
`feedback`
GROUP BY `feedback`.`id` , `feedback`.`value`
ORDER BY `feedback`.`date` DESC
What I would like to do, is instead have id, negative_messages, positive_messages, total_negative, total_positive, total.
idThe employee id.negative_messagesAn array of the last 5messagefor thatidwhich have avalue< 0.positive_messagesAn array of the last 5messagefor thatidwhich have avalue> 0.total_negativeTotal number of rows for thatidwithvalue< 0.- etc...
I could use help on where to begin.