I have a table, called feedback
, that contains: no
, date
, id
, message
, value
.
no
The row number.id
The employee id.message
Feedback from a customer.value
The feedback type. -1, 0, or 1.
Now I have a view which provides me with id
, messages
, total
, value
.
id
The employee id.messages
An array ofmessage
which shareid
andvalue
.total
The total number of rows which shareid
andvalue
.
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
.
id
The employee id.negative_messages
An array of the last 5message
for thatid
which have avalue
< 0.positive_messages
An array of the last 5message
for thatid
which have avalue
> 0.total_negative
Total number of rows for thatid
withvalue
< 0.- etc...
I could use help on where to begin.