Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check whether all my characters are same in MYSQL

I have a set of numbers and some numbers are starts with 000 and some numbers are contains only zeros like below.

select number,count(*) as attempts from num  where number like '0000%' group by number;

+------------------+-------+
| number           | attempts |
+------------------+-------+
| 0000             |     3 |
| 000000           |    16 |
| 00005124865151   |     1 |
| 0000000          |     1 |
| 00008816081588   |     1 |
+------------------+-------+
5 rows in set (1.40 sec)

Are there any method to get all zero numbers and numbers starts more than 3 zeros separately? I need all zeros as 20 and more than 3 zero numbers as 2.

Here is my try.. But seems this is wrong..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select date(date),
count(case when number like '0000%' then 1 else null end) as case1,
count(case when number like '0000%0' then 1 else null end) as case2 
from num  group by  date(date);

>Solution :

To test if it’s only zeroes, use a regular expression

SUM(number REGEXP '^0+$') AS case2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading