쿼리로 변환해야하는 도수 분 초의 행이 여러 개 있습니다.MySQL은 학위, 분, 초를 십진수로 변환합니다.
36 ° 19'11.46 "N = 36.31985
95 ° 36'02.22"W = 95.600617
각 행은 상이한 될 것이다. 나는 이틀 동안이 일에 매달 렸습니다. 이것은 가능한가?
쿼리로 변환해야하는 도수 분 초의 행이 여러 개 있습니다.MySQL은 학위, 분, 초를 십진수로 변환합니다.
36 ° 19'11.46 "N = 36.31985
95 ° 36'02.22"W = 95.600617
각 행은 상이한 될 것이다. 나는 이틀 동안이 일에 매달 렸습니다. 이것은 가능한가?
다음 작업을해야합니다 : 예를 들어
SELECT D + M/60 + S/3600;
, MySQL의에서 :
SELECT 36 + 19/60 + 11.46/3600;
반환 : 36.319850은
니스 lifehack : SEC_TO_TIME를 사용하여 문제 해결 (DMS에 정도) 역 건설 - MySQL의 함수 :
CREATE FUNCTION `geocoords`(lon double, lat double) RETURNS varchar(24) CHARSET cp1251
NO SQL
DETERMINISTIC
begin
declare alon double;
declare alat double;
declare slon varchar(12);
declare slat varchar(12);
set alon = abs(lon);
set alat = abs(lat);
set slon = TIME_FORMAT(SEC_TO_TIME(alon*3600), '%H°%i''%s"');
set slat = TIME_FORMAT(SEC_TO_TIME(alat*3600), '%H°%i''%s"');
if lon>0 then
set slon = concat(slon, 'E');
elseif lon<0 then
set slon = concat(slon, 'W');
end if;
if lat>0 then
set slat = concat(slat, 'N');
elseif lat<0 then
set slat = concat(slat, 'S');
end if;
return concat(slat, ' ', slon);
end
SELECT geocoords (30.550157546997, 50.344024658203)
50 ° 20'38 "N 30 ° 33'01"E
나는이 구축 결국, 그것은 내가 필요한 것과 완벽하게 일했다. C에 숫자를 추가했음을 알 수 있습니다.이 플래그는 플래그입니다. 이미 변환 된 경우 변환하지 않을 것입니다.
UPDATE
MasterTable
SET
MasterTable.Latitude_A = MasterTable.Latitude,
MasterTable.Longitude_A = MasterTable.Longitude
WHERE
ProjectID = 'ProjectAlpha'
and Sequence = '0'
and MasterTable.Latitude NOT LIKE '%C%'
and MasterTable.Longitude NOT LIKE '%C%';
TRUNCATE TABLE gpsconvert;
INSERT into gpsconvert(gpsconvert.`Account Number`,gpsconvert.Latitude,gpsconvert.Longitude)
SELECT
MasterTable.AccountNumber,
MasterTable.Latitude,
MasterTable.Longitude
FROM
MasterTable
WHERE
MasterTable.ProjectID = 'ProjectAlpha'
and MasterTable.Sequence = '0'
and MasterTable.Latitude NOT LIKE '%c%'
and MasterTable.Longitude NOT LIKE '%c%'
and MasterTable.Latitude <> ''
and MasterTable.Longitude <> '';
UPDATE
gpsconvert
SET
gpsconvert.LatDegree = LEFT(gpsconvert.Latitude,2),
gpsconvert.LatMinutes = SUBSTRING(gpsconvert.Latitude,-7,2),
gpsconvert.LatSeconds = SUBSTRING(gpsconvert.latitude,-5,5),
gpsconvert.LatDecimal = gpsconvert.LatDegree + (gpsconvert.LatMinutes/60) + (gpsconvert.LatSeconds/3600),
gpsconvert.LongDegree = LEFT(gpsconvert.Longitude,2),
gpsconvert.LongMinutes = SUBSTRING(gpsconvert.Longitude,-7,2),
gpsconvert.LongSeconds = SUBSTRING(gpsconvert.Longitude,-5,5),
gpsconvert.LongDecimal = gpsconvert.LongDegree + (gpsconvert.LongMinutes/60) + (gpsconvert.LongSeconds/3600);
UPDATE
MasterTable
INNER JOIN
gpsconvert on gpsconvert.`Account Number` = MasterTable.AccountNumber
SET
MasterTable.Latitude = CONCAT(gpsconvert.LatDecimal,'c'),
MasterTable.Longitude = CONCAT(gpsconvert.LongDecimal,'c')
WHERE
MasterTable.ProjectID = 'ProjectAlpha'
and MasterTable.Sequence = '0'
and MasterTable.AccountNumber = gpsconvert.`Account Number`
각 행이 변경되기 때문에 특정 D M S를 가져 오는 것이 어떻게 적절합니까? – Joker327
테이블 구조를 보지 않고도 대답하기가 어렵습니다. 하지만 아마도 다음과 같이 될 것입니다 : SELECT degrees + minutes/60 + seconds/3600 FROM tablename; – mti2935
이 작업을 더 쉽게하려면 무엇이 필요합니까? 각 DMS는 테이블에있는 열 전체에 있습니다. 약 1,000 개의 행이 있습니다. 각 행은 36 ° 19'24.52 "N과 같으며 그 다음 행은 36 ° 24'12.06"과 같습니다. N – Joker327