programing

MySQL: 두 필드를 결합하여 쿼리의 날짜/시간 필드 출력

skycolor 2023. 6. 6. 08:07
반응형

MySQL: 두 필드를 결합하여 쿼리의 날짜/시간 필드 출력

저는 두 개의 분야가 있습니다.

  1. teststartdatetime데이터 유형: datetime, 테스트 시작.
  2. testendtime데이터 유형: 중간 텍스트, "00:00:00" 형식의 종료 시간 텍스트

새 필드를 출력하려면 DB를 쿼리해야 합니다.testenddatetime의 시간 부분을 모두 포함하는 (날짜 시간 날짜 유형으로)testendtime필드 및 날짜teststartdatetime들판.

또한, 나는 그것이 필요하다 그것의 가치를 확인하기 위해.testendtime필드가 시간 부분의 값보다 나중입니다.teststartdatetime필드입니다. 그리고 그렇지 않다면,testenddatetime하루 걸러

참고: 테스트 시간은 24시간 이내입니다.

SQL Fiddle에서 자유롭게 가지고 놀 수 있습니다.

한다concat()당신이 원하는 것을 하십니까?

select concat(date(teststartdatetime), ' ', testendtime)

MySQL에 시간을 문자열로 저장하는 것은 정말 나쁜 생각입니다.time데이터 형식

수표의 경우:

select (case when time(teststartdatetime) > time(testendtime)
             then concat(date(teststartdatetime) + interval 1 day, ' ', testendtime)
             else concat(date(teststartdatetime), ' ', testendtime)
        end)

언급URL : https://stackoverflow.com/questions/66105080/mysql-output-datetime-field-in-query-by-combining-two-fields

반응형