very easy SQL question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zester
    Confirmed User
    • Jul 2003
    • 5344

    #1

    very easy SQL question

    I need a simply SQL query to get the amount of 'Approved' galleries I have in database, and the amount of 'Pending' galleries I have in database

    what do I use?

    it should be something like this:

    SELECT * count(status='Approved') approved, count(status='Pending') pending
    FROM galleries



    what do you say?
    * Mainstream ? $65 per sale
    * new male contraception
  • cfU
    Confirmed User
    • Jan 2003
    • 933

    #2
    select status, count(*)
    from galleries
    where status in ('Approved','Pending')
    group by status

    Comment

    • Nathan
      Confirmed User
      • Jul 2003
      • 3108

      #3
      SELECT SUM(IF(status='Approved',1,0)) approved, SUM(IF(status='Pending',1,0)) pending FROM galleries;
      "Think about it a little more and you'll agree with me, because you're smart and I'm right."
      - Charlie Munger

      Comment

      • Clarion
        Confirmed User
        • Jan 2005
        • 148

        #4
        I believe...

        SELECT * count(status='Approved') as approved, count(status='Pending') as pending
        FROM galleries

        ...it should work for ya.
        Structure Northwest :: the cure for the common code ::
        AIM: Asatruel | Yahoo!: Asatruel | ICQ: 111-638-053

        Comment

        • calmlikeabomb
          Confirmed User
          • May 2004
          • 1323

          #5
          Originally posted by Zester
          I need a simply SQL query to get the amount of 'Approved' galleries I have in database, and the amount of 'Pending' galleries I have in database

          what do I use?

          it should be something like this:

          SELECT * count(status='Approved') approved, count(status='Pending') pending
          FROM galleries



          what do you say?
          Code:
          $approvedquery = "SELECT * FROM galleries WHERE status='Approved'";
          $approved = @mysql_results($approvedquery);
          $numapproved = mysql_num_rows($approved);
          
          There are currently $numapproved approved galleries.
          That would be the correct way to do it......
          subarus.

          Comment

          Working...