gpt4 book ai didi

mysql - 选择一个 sql 字段并且不显示所选内容的特定单词

转载 作者:行者123 更新时间:2023-11-29 06:45:56 25 4
gpt4 key购买 nike

当此查询返回“中心”寄存器时,所有同名字段中都有一个我不想显示的单词。我可以通过 PHP 实现,但我需要在数据库上使用它。

基础知识我都知道,但是好久没做过sql了

SELECT
o.id_order,
o.reference AS Ref,
c.firstname AS Name,
c.lastname AS Last Name,
pl.`name` AS Center,
od.product_name AS Product,
od.product_quantity AS Quant,
ROUND(od.product_price * 1.21,2) AS Price,
o.date_add AS `Date`
FROM ps_orders AS o
INNER JOIN ps_order_detail AS od ON od.id_order = o.id_order
INNER JOIN ps_customer AS c ON c.id_customer = o.id_customer
INNER JOIN ps_product_lang AS pl ON pl.id_product = od.product_id
WHERE pl.id_lang = 1
ORDER BY od.id_order_detail DESC

当这返回中心数据时,所有字段前面都有介词“The”,返回类似:

Center 
The Odoo Team Center
The Dev house

然后我需要展示类似的内容

Center 
Odoo Team Center
Dev house

最佳答案

您可以使用REPLACE:

    SELECT
o.id_order,
o.reference AS Ref,
c.firstname AS Name,
c.lastname AS Last Name,
REPLACE(pl.`name`,"The ","") AS Center,
od.product_name AS Product,
od.product_quantity AS Quant,
ROUND(od.product_price * 1.21,2) AS Price,
o.date_add AS `Date`
FROM ps_orders AS o
INNER JOIN ps_order_detail AS od ON od.id_order = o.id_order
INNER JOIN ps_customer AS c ON c.id_customer = o.id_customer
INNER JOIN ps_product_lang AS pl ON pl.id_product = od.product_id
WHERE pl.id_lang = 1
ORDER BY od.id_order_detail DESC

Documentation: https://dev.mysql.com/doc/refman/5.7/en/replace.html

Demo: http://sqlfiddle.com/#!9/a5640/91

关于mysql - 选择一个 sql 字段并且不显示所选内容的特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49433397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com