2014-03-06 5 views
2

난 상태 3과 1에서 같은 이메일을 받았습니다 상태 3의 페이지에서 저를 보여주고 나 또한 여기에필터 SQL 결과?

상태 1로 그 이메일을 보내에만이 쿼리 상태 3 의 이메일을 보여줄 필요가 나의 쿼리입니다 :

둘 다 내부 조인과 왼쪽 가입 혼합 한
SELECT live_customers.Id, live_customers.date, 
     live_customers.firstname, live_customers.lastname, live_customers.phone, 
     live_customers.phone2, live_customers.email, live_customers.num_sellers, 
     live_customers.sell_date,live_customers.public_description, 
     live_customers.public_image, live_customers.price, 
     live_customers.takanon, live_customers.confirm_mail_sent, live_customers.paid, 
     live_customers.shirt_size, live_customers.shirt_size_extra, 
     live_customers.stand_rent, live_customers.refunded, live_customers.call1, 
     live_customers.call2, live_customers.notes, 
     live_customers.auth_number, live_customers.hasContact, live_customers.IP, 
     live_customers.status, live_status.name AS StatusName, 
     live_status.color AS StatusColor, live_compound.name AS CompoundName 
    FROM live_customers 
     INNER JOIN live_status 
        ON live_status.Id=live_customers.status   
     INNER JOIN 
     LEFT JOIN live_compound 
        ON live_compound.Id=live_customers.compound_id 
    WHERE live_customers.status='3'       
    GROUP BY 
     live_customers.Id 
    ORDER BY 
     live_customers.Id DESC 
    LIMIT 0,30 
+1

'INNER JOIN' 어떤 조건없이 쿼리가 잘못뿐만 아니라 제대로 –

+0

을 질문을 설명하고 쿼리의 문제는 무엇인가? 작동합니까? 작동하지 않습니까? 더 많은 정보와 세부 사항을 제공하십시오. – Prix

+0

상태 열의 데이터 유형은 문자 또는 숫자 –

답변

0

...

SELECT live_customers.Id, live_customers.date, 
     live_customers.firstname, live_customers.lastname, live_customers.phone, 
     live_customers.phone2, live_customers.email, live_customers.num_sellers, 
     live_customers.sell_date,live_customers.public_description, 
     live_customers.public_image, live_customers.price, 
     live_customers.takanon, live_customers.confirm_mail_sent, live_customers.paid, 
     live_customers.shirt_size, live_customers.shirt_size_extra, 
     live_customers.stand_rent, live_customers.refunded, live_customers.call1, 
     live_customers.call2, live_customers.notes, 
     live_customers.auth_number, live_customers.hasContact, live_customers.IP, 
     live_customers.status, live_status.name AS StatusName, 
     live_status.color AS StatusColor, live_compound.name AS CompoundName 
    FROM live_customers 
     INNER JOIN live_status 
        ON live_status.Id=live_customers.status   
     INNER JOIN live_compound 
        ON live_compound.Id=live_customers.compound_id 
    WHERE live_customers.status='3'       
    GROUP BY 
     live_customers.Id 
    ORDER BY 
     live_customers.Id DESC 
    LIMIT 0,30 
+0

이것은 좋지만 문제가있는 것과 같은 쿼리이다. 상태 3과 1에서 같은 이메일을 얻었다. 상태 3의 전자 메일 만 표시하려면 전자 메일의 상태가 3과 1이면 의미가 없습니다. – Victorino

0

내가 졸을 발견하십시오 내 문제의 ution. 여기있어. 이에게 유용 희망은 어떤 하나

SELECT live_customers.Id, live_customers.date, 
      live_customers.firstname, live_customers.lastname, live_customers.phone, 
      live_customers.phone2, live_customers.email, live_customers.num_sellers, 
      live_customers.sell_date,live_customers.public_description, 
      live_customers.public_image, live_customers.price, 
      live_customers.takanon, live_customers.confirm_mail_sent, live_customers.paid, 
      live_customers.shirt_size, live_customers.shirt_size_extra, 
      live_customers.stand_rent, live_customers.refunded, live_customers.call1, 
      live_customers.call2, live_customers.notes, 
      live_customers.auth_number, live_customers.hasContact, live_customers.IP, 
      live_customers.status, live_status.name AS StatusName, 
      live_status.color AS StatusColor, live_compound.name AS CompoundName 
    FROM live_customers 
     INNER JOIN live_status 
       ON live_status.Id=live_customers.status   
     INNER JOIN live_compound 
       ON live_compound.Id=live_customers.compound_id     

     WHERE live_customers.status='3' 
     AND live_customers.Email NOT IN (SELECT Email FROM live_customers WHERE status=1)     
     GROUP BY 
    live_customers.Id 
     ORDER BY 
    live_customers.Id DESC 
+1

집계 함수가 없을 때 GROUP BY를 사용하면 종종 실제로 하고있어. – Strawberry

+0

이 경우에는 지금 내가하고있는 일과 내가 필요한 것. 하지만 아무 래도 주셔서 감사합니다. – Victorino