-
Notifications
You must be signed in to change notification settings - Fork 0
/
useful sql.txt
29 lines (22 loc) · 1.47 KB
/
useful sql.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Remove trailing commas:
UPDATE businesses SET city_physical = SUBSTRING(city_physical, 1, char_length(city_physical) -1) where city_physical like '%,';
Revert cells to previous commit:
update schools as s1 set district=(select district from schools as of '66c1ac1j8phaga1ubf4fcra0og5gfo31' where name=s1.name AND city=s1.city AND state=s1.state)
update sales as s1 set district=(select district from schools as of '66c1ac1j8phaga1ubf4fcra0og5gfo31' where name=s1.name AND city=s1.city AND state=s1.state)
Title case strings:
update sic set description = CONCAT(UCASE(SUBSTRING(description, 1, 1)), LOWER(SUBSTRING(description, 2)));
Compare two sides of string:
UPDATE businesses
SET street_physical = SUBSTRING(street_physical, 1, LENGTH(street_physical) DIV 2)
WHERE
SUBSTRING(street_physical, 1, LENGTH(street_physical) DIV 2) = SUBSTRING(street_physical, LENGTH(street_physical) DIV 2 + 1, LENGTH(street_physical) DIV 2);
compare previous commit and revert based on outer where conditionthe
update hospitals, hospitals AS OF 'ksrc2pug8qjhkonf6dkqqgtij43hhp9p' as h2
set hospitals.homepage_url = h2.homepage_url
--select h1.homepage_url, h1.ccn, h2.homepage_url, h2.ccn from hospitals as h1
where
h2.ccn=hospitals.ccn
AND h2.state_code=hospitals.state_code
AND Char_length(hospitals.homepage_url) < Char_length(h2.homepage_url)
Add a / to the end of a string if it does not end in a /
UPDATE hospitals SET homepage_url = CONCAT(homepage_url, '/') WHERE RIGHT(homepage_url, 1) != '/'