过滤SQL结果?

时间:2014-03-06 08:51:33

标签: mysql sql

我在状态3和1中收到相同的电子邮件。我需要显示状态为3的电子邮件 使用此查询在状态3的页面中显示我,也通过电子邮件发送状态为1

这是我的问题:

 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

2 个答案:

答案 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

答案 1 :(得分: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'  
        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