当此查询返回"中心"注册,所有字段中都有一个与我不想显示的名称相同的单词。我可以通过PHP制作它,但我需要在db上使用它。
基础知识我知道,但我已经很长时间没有做过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
当这返回中心数据时,所有字段都有介词""在前面,返回类似的东西:
Center
The Odoo Team Center
The Dev house
然后我需要显示类似
的内容Center
Odoo Team Center
Dev house
答案 0 :(得分:1)
您可以使用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
答案 1 :(得分:0)
如果您总是想删除前四个字符,那么这样的事情应该有效:
SELECT SUBSTRING(center, 4, LENGTH(center)-3) FROM YOURTABLE;