phpmyadmin 正在尝试将WHERE子句添加到Mysql查询

f0brbegy  于 2022-11-09  发布在  PHP
关注(0)|答案(1)|浏览(138)

我尝试在这里添加一个where子句:

select `submission_id`, 
       max(case when `key` = 'id_usuario' then value end) as user,
       max(case when `key` = 'date_atualizado' then value end) as Data,
       max(case when `key` = 'peso' then value end) as Peso
from wp_e_submissions_values
group by `submission_id`

它工作得很好!但是我需要添加WHERE 'user' = 1

select `submission_id`, 
       max(case when `key` = 'id_usuario' then value end) as user,
       max(case when `key` = 'date_atualizado' then value end) as Data,
       max(case when `key` = 'peso' then value end) as Peso
from wp_e_submissions_values
WHERE 'user' = 1
group by `submission_id`

我在FROM之后添加了...但它不起作用。我收到以下错误:

Attention: #1292 Truncated wrong DOUBLE value: 'user'

你们能帮帮我吗?

wi3ka0sx

wi3ka0sx1#

仔细阅读您的问题后,看起来user上的Assert应该发生在HAVING子句中,而不是WHERE子句中。

SELECT
    submission_id,
    MAX(CASE WHEN `key` = 'id_usuario' THEN value END) AS user,
    MAX(CASE WHEN `key` = 'date_atualizado' THEN value END) AS Data,
    MAX(CASE WHEN `key` = 'peso' THEN value END) AS Peso
FROM wp_e_submissions_values
GROUP BY submission_id
HAVING user = 1;

相关问题