0

I have a mysql table below:

id   user_id   ticket 
1    39        56478939
2    51        42234951
3    40        56478940
4    52        67284952

Where ticket (for example for first row) = 564789 + 39 (user_id) My request looks like:

SELECT CONCAT_WS(";", id, user_id, ticket) FROM `signals` 

And I will get:

1;39;56478939
2;51;42234951
...

How can I get this type of data using MYSQL request (remove from ticket user_id at the end of ticket):

1;39;564789
2;51;422349
...

The request should be fast enough: Thanks you very much!

4 Answers 4

1

try this:

SELECT CONCAT_WS(";", id, user_id, LEFT(ticket,length(ticket)-length(user_id))) from table1;

FIDDLE DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

We don't know ticket length or length of user_id
0

Try this :

           SELECT CONCAT_WS(";", id, user_id, LEFT(ticket,6)) FROM `signals` 

1 Comment

@user889349 I've assumed your ticket length would be 6. Consider Joe's answer if its dynamic.
0

try this:

SELECT CONCAT_WS(";", id, user_id, left(ticket,length(ticket)-length(user_id)))
FROM `signals` 

Comments

0

You can use this query -

SELECT (ticket - user_id) DIV
  CASE
    WHEN user_id < 10 THEN 10
    WHEN user_id < 100 THEN 100
    ELSE 1000 END
FROM signals;

Add more WHEN cases if you need.

Then apply it to your query.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.