syntaxerror:missing)在mysql查询中的参数列表之后

bjg7j2ky  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(449)

我是新来的 node.js . 我已成功连接mysql数据库。我可以执行简单的select查询,但是当我尝试使用多个join的查询时,它会在参数列表之后抛出一个错误,即missing)

app.get('/quotes', function (req, res) {
mc.query(`SELECT p.sku,pa.attribute_value as is_seen, pa1.attribute_value as rating,m.projects_unit_id as project_id,m.version,sp.total_sale_price as total_price,
    p.published_on,im.image_url as image, im1.image_url as  pdf_link FROM my_designs m INNER JOIN product p on m.sku=p.sku and p.is_deleted=0 and p.is_published=1 
    INNER JOIN supplier_product sp on sp.product_id=p.product_id and sp.is_deleted=0 
    LEFT JOIN images im on im.`key`=m.sku and im.image_type=36 and im.is_deleted=0 
    LEFT JOIN images im1 on im1.`key` = m.sku and im1.image_type = 15 and im1.is_deleted=0 
    LEFT JOIN product_attributes pa on pa.common_id = p.sku and pa.is_deleted = 0 and pa.attribute_name = 'is_seen' 
    LEFT JOIN product_attributes pa1 on pa1.common_id = p.sku and pa1.is_deleted = 0 and pa1.attribute_name = 'rating' 
    WHERE m.user_id=? and m.is_deleted=0 and m.projects_unit_id is not null ORDER BY p.published_on DESC`, function (error, results, fields) {
    if (error) throw error;
    return res.send({ error: false, data: JSON.stringify(results), message: 'quote list.' });
}); });

请告诉我哪里出了问题。

kuuvgm7e

kuuvgm7e1#

您正在尝试使用模板文本。你需要使用 $ 在变量周围,这就是您需要编写查询的方式,

`Select * from Table where key = ${key} and otherkey = ${otherkey}`
ddrv8njm

ddrv8njm2#

因为您使用的是模板文本
模板文本由 back-tick (``) (重音符)代替双引号或单引号的字符。
模板文本可以包含占位符。这些由美元符号和花括号表示 (${expression}) .
这是文件
所以,你必须用“key”代替im im.${key} 所以,你的代码变成,

app.get('/quotes', function (req, res) {

mc.query(`SELECT p.sku,pa.attribute_value as is_seen, pa1.attribute_value as rating,m.projects_unit_id as project_id,m.version,sp.total_sale_price as total_price,
    p.published_on,im.image_url as image, im1.image_url as  pdf_link FROM my_designs m INNER JOIN product p on m.sku=p.sku and p.is_deleted=0 and p.is_published=1 
    INNER JOIN supplier_product sp on sp.product_id=p.product_id and sp.is_deleted=0 
    LEFT JOIN images im on im.${key}=m.sku and im.image_type=36 and im.is_deleted=0 
    LEFT JOIN images im1 on im1.${key} = m.sku and im1.image_type = 15 and im1.is_deleted=0 
    LEFT JOIN product_attributes pa on pa.common_id = p.sku and pa.is_deleted = 0 and pa.attribute_name = 'is_seen' 
    LEFT JOIN product_attributes pa1 on pa1.common_id = p.sku and pa1.is_deleted = 0 and pa1.attribute_name = 'rating' 
    WHERE m.user_id=? and m.is_deleted=0 and m.projects_unit_id is not null ORDER BY p.published_on DESC`, function (error, results, fields) {
    if (error) throw error;
    return res.send({ error: false, data: JSON.stringify(results), message: 'Todos list.' });
    }
);

});

附言:
你有理由让其他人知道,关键是 reserved 一句话。

相关问题