Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    6

    Unanswered: SQL Command HELP ME pls

    can you help me guys the sql command for this scenario.


    I want to know the distinct numbers who has billingflag=0 count is less than 5.

    I have this sql command but it returned wrong output

    select distinct number,billingflag from utang_entries where date<date_sub(now(),interval 7 day) group by number having count(billingflag)<3 and billingflag=0

    and i tried this too,

    select distinct number,billingflag from utang_entries where date<date_sub(now(),interval 7 day) group by number having count(billingflag=0)<3


    Hoping for your quick response.

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by msashin View Post
    I have this sql command but it returned wrong output
    what did it actually return? what should it have returned?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2012
    Posts
    6
    Hello,

    Example i have three distinct numbers: 9999,8888,7777 together with there corresponding flags. the rule is i need to get the number that the count of 0 flag/s is less than 3. Therefore the sql must return the 999 and 7777 numbers.
    My current command,as i mentioned above, didnt work.

    number flag
    9999 0
    9999 1
    9999 1
    8888 1
    8888 1
    8888 1
    7777 0
    7777 0
    7777 1


    I hope you can help me..

    Thanks.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by msashin View Post
    i need to get the number that the count of 0 flag/s is less than 3.
    Code:
    SELECT number
     WHERE flag = 0
    GROUP
        BY number
    HAVING COUNT(*) < 3
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Aug 2012
    Posts
    6

    Thumbs up

    Quote Originally Posted by r937 View Post
    Code:
    SELECT number
     WHERE flag = 0
    GROUP
        BY number
    HAVING COUNT(*) < 3

    Horray thank you so much.. Got it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •