Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'd like a MySQL query to achieve the following :
I have 10000 rows that look like this
Source 1::https://domainxyz.com//public/dist/s2q1sd65az7r/index.html||Source 2::https://domainabc.com/embed-8eel8v83lefs.html||Source 3::https://domainqsd.com/v/w1qy8g81w6||Source 5:://domainwxc.com/embed2.php?link=5fUE7Mo%25
Only the links are different from one row to another
I'd like to remove all content related to Source 1
That content would be anything between "Source 1" and "||" (including the removal of the string "source 1")
So in my exemple, that would removing this :
Source 1::https://domainxyz.com//public/dist/index.html
PS : it also possible that "Source 1" data has no "||" at the end (when the data is at the end of the ligne)
You can use regexp_replace():
select regexp_replace(concat(str, '||'), 'Source 1::[^|]*[|][|]', '')
from (select 'Source 1::https://domainxyz.com//public/dist/s2q1sd65az7r/index.html||Source 2::https://domainabc.com/embed-8eel8v83lefs.html||Source 3::https://domainqsd.com/v/w1qy8g81w6||Source 5:://domainwxc.com/embed2.php?link=5fUE7Mo%25' as str
) t
Or alternatively as:
select regexp_replace(str, 'Source 1::[^|]*([|][|]|$)', '')
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a table in SQL Server where a row contains a Json column - something like this:
ResponseText
RequestId
{"LosUnqCod":0,"LosMidId":23}
96173722
{"LosUnqCod":1,"LosMidId":5}
96173721
I want to have a table in this shape:
LosUnqCod
LosMidId
RequestId
0
23
96173722
1
5
96173721
how to open this json?
Hi every body I found my answer and want to share with anyone who has the same issue as I does
SELECT
reqTbl.LosUnqCod ,
a.RequestId
FROM [dbo].[a] CROSS APPLY
OPENJSON( dbo.a.responsetext)
WITH (
LosUnqCod nvarchar(50)
) AS reqTbl
You don't have to use OPENJSON if you only have one JSON object (not an array) per SQL row, you can use JSON_VALUE instead:
SELECT
JSON_VALUE(a.responsetext, '$.LosUnqCod') LosUnqCod,
JSON_VALUE(a.responsetext, '$.LosMidId') LosMidId,
a.RequestId
FROM [dbo].[a];
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
i have a database (mysql) with links like:
mysite.com/Movies/Abajan_1080p.mp4
mysite.com/Movies/Abajan_720p.mp4
mysite.com/Movies/Abajan_480p.mp4
mysite.com/Movies/Bahman_1080p.mp4
mysite.com/Movies/Bahman_720p.mp4
mysite.com/Movies/Bahman_480p.mp4
....
i sorted my files by creating directories by alphabets (A,B,...)
so i need to change links:
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
is there a simple solution to edit database? to edit all links like that?
Thanks a lot
You can use the function SUBSTRING_INDEX() to get the filename and then concatenate the path:
UPDATE tablename
SET col = CONCAT(
'mysite.com/Movies/',
LEFT(SUBSTRING_INDEX(col, '/', -1), 1),
'/',
SUBSTRING_INDEX(col, '/', -1)
)
Replace col with your column's name.
See the demo.
Results:
col
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a database where i store my photos title, tags, and their path on sever some of the records have names like:
photo 1234.png. I need to make them like photo1234.png
Why can't I use a query like
UPDATE tblPhoto a
set a.photoLink = replace(a.photoLink , ' ', '')
where a.photoLink like '% %';
And which is the best way to rename them in Linux Server, can I use php ?
You don't need where clause
UPDATE tblPhoto SET photoLink = REPLACE(photoLink , ' ', '');
For replacing the file name on your Linux Server you can try to look in this answer.
https://stackoverflow.com/a/2709619/7921383
Use php method for example:
$old_name="Hello World";
echo str_replace(" ","",$old_name);
//output Helloworld
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have 3 mysql queries in php (one for each category/widget), all 3 queries together should output 3 * 6 = 18 results. So if one query returns less, more results from the other queries should be used.
How can i do that? Thanks.
Instantiate 2 variables , keep count of selected rows and execute query using these counters
for example this will be your first query execiton
$default = 6;
$limit= $default;
$some_result = mysql("SELECT * FROM table LIMIT $limit");
then you can use this for every query-limit
$limit = $limit - count($some_result) + $default;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can i use nested Case statements in t-sql as i have done and also "*" used for multiplcation in the access query can it be used in the same way in T-sql for example
([Col2]*[col3])
MS Access:
IIf(IsNull([Col1]),([Col2]*[col3]),([col2]*[col3]/[col1])) as Column
T-Sql:
Case When [Col1] Is Null then ([Col2]*[col3])
else ([col2]*[col3]/[col1]) end AS column
Ms Access:
IIf(Left([col],1)=3,"Tran",IIf(Left([ss],1)=7,"Con","Sto")) AS [col]
T-sql:
(Case When (Left([col],1)=3) then 'Tran' else (Case When (Left([col],1)=7) then 'Con' else 'Sto' end )end) AS [col type]
Your 2nd TSQ should look like this:
CASE
WHEN LEFT([col],1)=3 THEN 'Tran'
WHEN LEFT([col],1)=7 THEN 'Con'
ELSE 'Sto'
END AS [col type]
As far as # you don't need that in SQL, just put the date value in single quotes correctly formatted.