Mysql Select Query

Last post 11-07-2009 11:14 AM by TinyPond. 3 replies.

Sort Posts:

  • Mysql Select Query

    10-29-2009, 2:48 PM
    • Member
      223 point Member
    • masterpage1
    • Member since 02-25-2008, 2:41 PM
    • West Chester
    • Posts 159

    Ok, i have a question about a select query

    lets say i have two tables

    we call them

    customers with the following fields customerID, dateentered, status

     and customermembers with the following fields

    customerid, membershipid, purchasedate, status.

    what i wanted to do is get all customers that do not have membership and the customers that had memberships but was cancelled, terminated, expired. and count them all

    the problem i am having our database is not really good for example there could be a customer that had a membership but reactivated it later so if i select the non active members this customer should not show up on my list but the problem is he does show up because of the customer history.

    how can i get arround this. this is making me crazy as simple it may sounds i am stuck.

    any help is apreciated.

    Toure
  • Re: Mysql Select Query

    10-29-2009, 5:03 PM
    • Participant
      1,994 point Participant
    • s10n
    • Member since 01-12-2007, 5:16 PM
    • El Salvador
    • Posts 425

    Can you post the query you are using?

  • Re: Mysql Select Query

    11-02-2009, 12:27 PM
    • Member
      223 point Member
    • masterpage1
    • Member since 02-25-2008, 2:41 PM
    • West Chester
    • Posts 159

    here it is but some how it is counting all records from active to frozen to on hold even though i excluded them

    Select COUNT(customers.customernumber) as Total, locations.storelocation,customers.customernumber FROM locations
    INNER JOIN(customers INNER JOIN customermemberships ON customers.customernumber = customermemberships.customernumber)
    ON customers.locationcode = locations.locationcode
    WHERE customers.dateentered >='2009-03-01'
    AND customermemberships.customernumber NOT IN("Active","Frozen","On Hold")
    GROUP BY customers.customernumber;

    Thanks for your prompt response. 

    Toure
  • Re: Mysql Select Query

    11-07-2009, 11:14 AM
    • Member
      440 point Member
    • TinyPond
    • Member since 07-28-2002, 6:39 PM
    • North West USA
    • Posts 116

    Your query is correct, hower you have the following 

    customermemberships.customernumber NOT IN("Active","Frozen","On Hold") 

    above you are joining customers.customernumber with customermembership.customernumber, I would guess the values in customernumber are not "active" or "frozen" or "onHold"


    you have the following tables

    locations , customers, customermembers  do you need all three of these tables in this query? I would suggest simplificatoin and then add to it once its working.












    TinyPond
Page 1 of 1 (4 items)