我想做一个需要两个表的查询。查询的目的是返回treduit或tplein列(在表tarif中)的值,具体取决于grilletarif和iduser列(表client)中写入的内容。
第一个表:客户端
nom prenom mail adresse idUser grilleTarif
admin admin admin@admin.com 10 rue de l'admin m(à"éàé"àé'à_ç-&'à&&=&-&é&à&&&é(è&é_è(§ tPlein
第二张table:tarif
tReduit tPlein nomActivity nPlace
2 3 NULL NULL
7 8 aquaPoney 10
我的问题:
SELECT
tarif.tReduit,
tarif.tPlein,
client.grilleTarif,
CASE grilleTarif
WHEN 'tReduit'
THEN tarif.tReduit
WHEN 'tPlein'
THEN tarif.tPlein
ELSE tarif.tPlein
END AS X
FROM tarif, client
WHERE client.idUser = m(à"éàé"àé'à_ç-&'à&&=&-&é&à&&&é(è&é_èpp§, tarif.nomActivity IS NULL;
我执行它时出现语法错误。
# 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE grilleTarif WHEN 'tReduit' then tarif.tReduit when 'tPlein' then tarif.tPle' at line 1.
Unrecognized keyword. (near "AS" at position 153)
Unexpected token.(near "tarif" at position 156)
Unexpected token. (near "." at position161)
Unexpected token. (near "tPlein" at position 162)
我尝试执行的另一个查询是如何在动态查询中将行值连接到列名
SELECT grilleTarif FROM client c
INNER JOIN
( SELECT tarifCol, tarif from tarif t
unpivot
(
tarif
for tarifCol in ([tPlein], [tReduit])
) unpiv
) d
on c.grilleTarif=t.tarifCol
where c.idUser = m(à"éàé"àé'à_ç-&'à&&=&-&é&à&&&é(è&é_è(§
and t.nomActivity is NULL;
我还有语法错误#1064
[...]near 'unpivot (tarif for tarifCol in ([tPlein], [tReduit])) unpiv )
Unexpected character. (near "[" at position 114)
Unexpected character. (near "]" at position 121)
Unexpected character. (near "[" at position 124)
Unexpected character. (near "]" at position 132)
1条答案
按热度按时间bnlyeluc1#
op解决方案。
查询函数: