| |

VerySource

 Forgot password?
 Register
Search
View: 1355|Reply: 4

SQL statement query maximum problem

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2021-3-2 12:30:01
| Show all posts |Read mode
Table RUNCARD has M, N and other fields
The data in M ​​such as M(1)=mm001
             M(2)=mm002
             M(3)=mm003
             ......
    Type varchar
Now I want to make a loop, extract the maximum value from the number part after mm in M, and attach it to num, the type is integer

Can you please take a look at my sentence?
SELECT MAX(CAST(SUBSTRING(M,2,9) AS INTEGER)) AS NUM FROM RUNCARD

I feel that the type conversion is a bit messy, please expert advice, thank you, urgent! ! !
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2021-3-2 12:45:01
| Show all posts
SELECT MAX(CAST(SUBSTRING(M,3,9) AS INT)) AS NUM FROM RUNCARD
Reply

Use magic Report

1

Threads

13

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2021-3-2 14:15:02
| Show all posts
That's right,michealhenry, that's right
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2021-3-2 15:00:01
| Show all posts
this is okay too:)
SELECT MAX(cast(REPLACE(M,'mm','') AS INT)) AS NUM FROM RUNCARD
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2021-3-2 15:15:01
| Show all posts
this is okay too
select cast(right((select max(m) from runcard),3) as int) as num
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list