简体   繁体   中英

How to 'Create a table based on a query and delete from first 3 characters to the right'

I have a simply query:

select pcode, description from outerb where pcode like '123%'

Here is a fiddle link to show you where I got to:

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=bf44b07918374985074084552e7b7005

How would I create a new table based on the query above, but removing all characters to the right from 3rd character?

This is my expected output

pcode   description 
123        TEST     
123        TEST    

I think you want the left() function:

select left(pcode, 3) as pcode, description, size
from table1;

You can use substring(string, start, length)

SELECT substring(pcode, 1, 3) AS pcode,
       description,
       size
FROM table1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM