This question already has answers here:
How to extract two consecutive digits from a text field in MySQL?
(7 answers)
How to extract the nth word and count word occurrences in a MySQL string?
(9 answers)
Closed 6 years ago.
I am trying to get year (yyyy) from text/string in the column "title" but for some reason can't get following query to work:
select substring(title,LOCATE(REGEXP '[(][0-9]{4}[)]',title),4) from videos
title column has following values:
abc abc 2001 abc
xyz (2002) xyz
Any assistance will be appreciated.
Related
This question already has answers here:
Count boolean field values within a single query
(4 answers)
Closed 4 months ago.
Suppose a table have a column with values like:
column
3
1
1
3
4
1
2
I want to retrieve that how many times there is 1 in column and how many times > 1.
Is there anyway to do this within one query?
I want the data to be fetched like this:
one | greater_than_one
3 | 4
Thanks in advance.
Simple:
select sum(col1=1) as one ,
sum(col1>1) as greater_than_one
from test_tbl;
https://dbfiddle.uk/348f5YOK
This question already has answers here:
Search with comma-separated value mysql
(1 answer)
Is storing a delimited list in a database column really that bad?
(10 answers)
Closed 11 months ago.
I have this table units
id
value
1
value 1
2
value 2
3
value 3
and another table called users
id_units
concat_value
1,2
---
1,3,2
---
what I'm struggling with is how can I show on the concat_value column all the values separated by comma for each of the ids on the id_units field?
I need it to look like this
id_units
concat_value
1,2
value 1,value2
1,3,2
value 1,value3,value2
This question already has answers here:
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
(12 answers)
How to make a query with group_concat in sql server [duplicate]
(4 answers)
Closed 3 years ago.
I have a simple query that does group concat very well in SQL workbench.
id hobby
1 dance
1 sing
2 play
2 sing
Expected output:
id hobby
1 dance,sing
2 play,sing
How can I get this output using MS SQL Server?
This question already has answers here:
mysql count the sum of all rows
(6 answers)
Closed 6 years ago.
I have a SQL table that looks like this:
id | value
-----------------------
1 | 5
2 | 5
3 | 6
I want to count the value of every rows.
In this example the output should be 16.
What query should I use to count the total value of the rows?
You can learn more about COUNT() Function there.
https://www.w3schools.com/sql/sql_func_count.asp
This question already has an answer here:
MySQL : Multiple row as comma separated single row
(1 answer)
Closed 9 years ago.
Here is my table information
Id Name
1 aaa
1 bbb
2 ccc
2 ddd
Ids are the repeated one. Now I want the result like
1 aaa,bbb
2 ccc,ddd
How can I do that in Mysql ?
Use GROUP_CONCAT()
select id, group_concat(name) as names
from your_table
group by id