To be more specific, if the original string column is like
'AAA 123 BBB 456'
'CCC 234 DDD EEE 678'
'FFFFF 7280 ZZZ 123 DDD'
what I need eventually is the first cluster of numbers only, like
'123'
'234'
'7280'
TIA
Use regexp_extract function:
select regexp_extract('AAA 123 BBB 456','[0-9]+',0) - digit one or more times
returns 123
Related
I am trying to explode values belonging to one id into multiple rows.
category_id subcategory_ids
123 111
123
333
465 444
555
The result I am trying to achieve should look like below-
category_id subcategory_ids
123 111
123 123
123 333
465 444
465 555
Below is for BigQuery Standard SQL
#standardSQL
SELECT category_id, subcategory_ids
FROM `project.dataset.table`,
UNNEST(subcategory_ids) subcategory_ids
I am working on a query and having a difficult time to figure out how to fill the same value based on one column. Let me explain what I am trying to accomplish....
Says, I have a table like this below with too columns: Name & Value. So, "Select Name, Value FROM Table1 Order By Name" will produce the following result.
Table1
Name Value
AAA 111
AAA
BBB 222
BBB
BBB
BBB
CCC 333
CCC
DDD 444
DDD
DDD
Now, What I am trying to accomplish is producing the result below with the "Select .... from Table1" query.
Table1
Name Value
AAA 111
AAA 111
BBB 222
BBB 222
BBB 222
BBB 222
CCC 333
CCC 333
DDD 444
DDD 444
DDD 444
Please help and provide the sample code if possible.
Thanks in advance
You can use MAX() as a window function:
SELECT Name, Value,
MAX(Value) OVER (PARTITION BY Name) as imputed_name
FROM Table1
ORDER BY Name;
I have a table with the following columns.
DATE - CUSTOMER - COLOR - JOBNAME -ORDERNUM
I can't figure out how to write a query to return rows that have the same JOBNAME but different date.
Let's say I have
1/9 AAA GREEN JOHN 1235
1/9 AAA GREEN JOHN 1236
1/9 AAA GREEN JOHN 1237
1/8 AAA GREEN JOHN 1238
1/9 BBB ORANGE MATT 1239
1/9 BBB ORANGE MATT 1240
1/12 CCC PINK BRETT 1241
1/5 DDD YELLOW JASON 1242
1/5 DDD YELLOW JASON 1243
I want the query to return only
1/9 AAA GREEN JOHN 1235
1/9 AAA GREEN JOHN 1236
1/9 AAA GREEN JOHN 1237
1/8 AAA GREEN JOHN 1238
because they have the same JOBNAME but different dates.
I would start by getting the list of jobs with different dates:
select jobname
from table
group by jobname
having min(date) <> max(date);
If you want the complete list, then use join or in or exists:
select t.*
from table as t
where t.jobname in (select jobname
from table
group by jobname
having min(date) <> max(date)
);
Did I completely misunderstand something, or are you not just looking for:
SELECT *
FROM MyTable
WHERE JobName = "JOHN"
Because that's basically what your result set is, and it fits your request.
i have this table MEN
Fname
aaa
bbb
ccc
aaa
aaa
bbb
ggg
i need query that replace all the aaa - in - ZZZ
Fname
ZZZ
bbb
ccc
ZZZ
ZZZ
bbb
ggg
how to do it on Oracle query ?
thanks in advance
Will work not only in Oracle
update MEN
set Fname='ZZZ'
where Fname='aaa';
UPDATE MEN SET Fname='ZZZ' WHERE Fname='aaa';
see http://psoug.org/reference/update.html
I have table:
name marks
aaa 100
aaa 56
aaa 120
bbb 56
bbb 60
The result should be:
aaa 120
bbb 60
ie unique name with maximum marks. Is there any query in mysql?
SELECT name, MAX(marks) marks
from table
group by name