omu1004
152
2019-03-28 13:21:28
1
161

DISTINCT 사용 시 첫번째 데이터가 안나옵니다..ㅠ


"SELECT DISTINCT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

        WHERE MR_MtRoom_TB_MtRoom_NO NOT IN (

            SELECT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

            WHERE mr_info_date = '2019-03-31' AND mr_info_stime < '$tselectEtime' AND mr_info_etime > '$tselectStime')"


결과 : 

[{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"5"},{"MR_MtRoom_TB_MtRoom_NO":"6"},{"MR_MtRoom_TB_MtRoom_NO":"7"}]


"SELECT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

        WHERE MR_MtRoom_TB_MtRoom_NO NOT IN (

            SELECT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

            WHERE mr_info_date = '2019-03-31' AND mr_info_stime < '$tselectEtime' AND mr_info_etime > '$tselectStime')"


결과 : 

[{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"7"},{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"4"},{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"3"},{"MR_MtRoom_TB_MtRoom_NO":"5"},{"MR_MtRoom_TB_MtRoom_NO":"6"},{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"1"},{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"2"},{"MR_MtRoom_TB_MtRoom_NO":"7"},{"MR_MtRoom_TB_MtRoom_NO":"7"},{"MR_MtRoom_TB_MtRoom_NO":"7"},{"MR_MtRoom_TB_MtRoom_NO":"3"},

원래 쿼리결과는 1~7의 값이 다나와야하는데 중복 데이터를 제거하려고

DISTINCT를 사용했습니다. 그런데 1값이 안나오네요 왜그런지 아는 고수님 계신가요


0
0
  • 답변 1

  • 이설란
    461
    2019-03-28 13:59:48

    음...distinct가 가끔 뻘짓을 하긴하지만...정확한 이유는 모르겠고....

    DB데이터가 제게 있는게 아니라서 테스트 불가라 설명은 못드리지만

    해당 결과를 정상적으로 보고 싶으시다면


    SELECT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

            WHERE MR_MtRoom_TB_MtRoom_NO NOT IN (

                SELECT MR_MtRoom_TB_MtRoom_NO from mr_info_tb

                WHERE mr_info_date = '2019-03-31' AND mr_info_stime < '$tselectEtime' AND mr_info_etime > '$tselectStime') GROUP BY  MR_MtRoom_TB_MtRoom_NO


    이렇게 사용하시면 나올 것 같습니다. 객수가 궁금하시면 맨위에 COUNT(*)를 추가하셔서

    보셔도 될 것 같구요~


    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.