Does anyone feel like being nice and helping me with an sql problem?

i know its not java but ive posted on sql forums and got no where, so i was hoping someone here would know how to do what i want to do
the link to the forum post is
http://forums.mysql.com/read.php?10,49695,49695#msg-49695
the basic thing is
im trying to sort a shopping basket into the most popular products
so if the data was
basketID||orderID||productID||quantity
1||1||2||1
2||1||3||6
3||1||4||1
4||2||2||1
5||2||4||1
6||3||4||1
then im using this statement
SELECT productID,COUNT(*) AS cat_num FROM shopbasket_table GROUP BY productID ORDER BY cat_num DESC LIMIT 0,10
which sorts them like
productID
4
2
3
but this doesnt take in to account the quantity in the basket which it really should
as product 3 has 6 in the basket
so it should be
3
4
2
anyone know enough about sql to know what im missing from my statement?
sorry again for posting on the java forum, u peeps are just super smart though and im sure someone here would know :)

I don't know how to do it in mysql, but it appears to be a "crosstab" kind of problem. This article may help

Similar Messages

  • Please help me with PL/SQL problem

    Hi to all
    This is my problem. I have a database with several tables. I will mention just some important for this problem. I have a table called Invoice, where I have following atributes
    sifrac number(9) not null primary key,
    datrac date default sysdate,
    sifkup number(5),
    sifprod number(5) not null,
    ukcena number(5,2)
    Then I have table called History of customer where I have
    constraint pk_istkup primary key(sifrac,sifkup),
    sifrac number(9) constraint fk_sifrac2 references racun(sifrac),
    sifkup number(5) constraint fk_sifkup3 references kupac(sifkup) this is primary key in a table customer,
    datrac date default sysdate,
    ukcena number(5,2) this is total price of purchased stuff per one invoice.
    What I would like to do now is make a trigger before insert or update table Invoice which check table History of customer and make a calculation of all total prices per one customer and if that customer made a purchase which is more than 1000 dollars then it have to make a calculation of total price*discount percent.How can I do that.
    Thanks to all in advance

    Billy  Verreynne  wrote:
    LKBrwn_DBA wrote:
    This type of functionality (a business rule to compute discount) would normally be added at the application level and not in a trigger. Why? Does business rule code need Java to be expressed correctly? Does Java (or whatever application layer language) used provide a better set of instructions for doing business rules than PL/SQL? Is business code written using a special keyboard and a pretty font?
    And what happens when new system feeds invoice data for new department/division directly into the database, bypassing the app layer? What happens to that app layer business logic now?
    It is a fallacy that business rules and logic needs to reside in a separate layer as that is somehow better. I disagree. LKBrwn_DBA didn't mention Java as an application layer. And he was not strict about it. So yes it is possible to use a trigger. But business logic tends to be changed fequently. So the rules for the logic might change. I would implement such logic using a pacakged pl/sql api. Triggers I would use for data validations and checks that are less likely to be changed.
    As always it depends. But the general advice to have a certain level of business logic (e.g. apis) and another level of data integration and consitency layer (e.g. constraints and triggers) is a good advice.
    As for bypassing the application layer. If an new system is able to do that, it can wreck even more havoc. A good anti mechanism is to expose only the APIs layer in a separate schema. The new system will have access to the schema and to the packages that are specified there. But it won't have direct dml to the tables.
    Main question for me would be: Is that a business rule or is it a data integration rule (e.g. keep redundant data in different tables harmonized). This influences where the logic will be implemented.
    Edited by: Sven W. on Oct 2, 2009 8:59 AM

  • Keep receiving "USB Over Current Notices" since updating to OSX 10.6.8. I have no devices plugged into my Imac and running everything wireless. SMB/PRAM resetting did not work. Does anyone have some advice or can help?

    Keep receiving "USB Over Current Notices" since updating to OSX 10.6.8. I have no devices plugged into my Imac and running everything wireless. SMC/PRAM resetting did not work. Does anyone have some advice or can help?

    Hi Melissa,
    Pretty strange, but...
    Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, does it happen in Safe Mode? Reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

  • I have had apple products since day dot and why since steve jobs died does it feel like apple are going to ****!is it cos the big corporations have got hold of it and its price over passion

    I have had apple products since day dot and why since steve jobs died does it feel like apple are going to ****!is it cos the big corporations have got hold of it and its price over passion

    thankyou. THANK you.
    thankyouthankyouthankyou!
    sorry about no screenie but the first option worked (at least so far!)
    THANKYOUTHANKYOUTHANKYOUTHANKYOUTHANKYOUTHANKYOUTHANKYOUTHANKYOU

  • I ned help please, I am losing storage space on my iPhone 6 and I am not downloading anything nor upgrading but still my storage dwindles literally by the hour , does anyone know as to why and if so how to stop this please and thank you.

    I ned help please, I am losing storage space on my iPhone 6 and I am not downloading anything nor upgrading but still my storage dwindles literally by the hour , does anyone know as to why and if so how to stop this please and thank you.

    Did you tried any of these basic troubleshooting steps?
    Restart / Reset
    http://support.apple.com/en-us/HT201559
    Restore from backup
    Restore as new
    http://support.apple.com/en-us/HT201252

  • Is the ipod shuffle or nano good for exercise if you just use the clip on the unit, and connect to your shorts?  if so, does it feel like it's too loose, might fall off?

    is the ipod shuffle or nano good for exercise if you just use the clip on the unit, and connect to your shorts?  if so, does it feel like it's too loose, might fall off?

    I often use my shuffle while exercising, cleaning, and just generally going about my day. Never once has it come unclipped exept for when I got the earbud cord caught on something and got said earbuds yanked out of my ears. I have permanently solved that problem by simply running the cord under my shirt. Works like a charm! I can't answer you about the nano, though I'd say it has a higher likelihood of coming off as it is a bit heavier.

  • Does anyone know anything about iPhones and/or iPads having barcode scanners for business purposes?

    Does anyone know anything about iPhones and/or iPads having barcode scanners for business purposes?  I am doing some research about the benefits of using a Q R Code type of system, but question which handheld sets would be more compatible for using that type of barcode.  Being a avid Apple supporter, I cannot seem to find very much research on this specific topic.
    Any thoughts?

    I have a QR reader on my iphone. Works just brill. I've used it to create business cards, with a boat load more information on it (Including my duty times, etc)
    Most of the QR readers in the App store are free, so give them a try. You can copy and paste the data just like normal text.
    What application for them did you have in mind?

  • Does anyone know why the delete and hide options are still missing in the crop tool option bar, despite having changed the background layer to a regular layer?  Thanks!

    Does anyone know why the delete and hide options are still missing in the crop tool option bar, despite having changed the background layer to a regular layer?  Thanks!

    "flying blind."
    "You totally lost me there, and I have no clue as to what your last question means."
    "I think I now know what you mean."
    Evidently language is of difficulty for you. 
    Perhaps the Oxford dictionary can provide you with your much needed “sensible, meaningful” content.
    According to the Oxford dictionary, a dialogue is to "Take part in a conversation or discussion to resolve a problem."  It also states that a dialogue is "A discussion between two or more people or groups, especially one directed toward exploration of a particular subject or resolution of a problem.”
    That IS the inherent nature of posts. A conversation is reciprocation.  Questions, followed by more questions.
    It is not difficult to understand.
    "how to ask your questions correctly for quicker and better answers" is best actualized by simply asking.
    Is it a Mac; is it not, etc.
    That IS sufficient.  That IS "quicker and better answers[ing]."  That IS what a dialogue IS.   And that IS actually what is "sensible," "meaningful," and "detailed." 
    The Oxford dictionary can best delineate and elucidate your lack of comprehension in what ACTUALLY “meaning” is.
    As well as what is "sensible" AND "detailed." 
    By the way, am I being repetitive.
    Still confused.  Let the experts that do not require much explanation respond with "quicker and better answers" for both "sensible, complete" responses." They are not "lost," "blind," or provide "incomplete" drivel.

  • TS4291 I can't send mail from my iPad apps, I just get the error message, 'The recipient- was rejected by the server because it does not allow relaying.' Does anyone know what this means and how to fix the problem.

    I can't send mail from my iPad apps, I just get the error message, 'The recipient… was rejected by the server because it does not allow relaying.' Does anyone know what this means and how to fix the problem.

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    Using a POP account with multiple devices
    http://support.apple.com/kb/ht3228
    iOS: Adding an email account
    http://support.apple.com/kb/HT4810
    iOS: Setting up an Outlook.com, Hotmail, Live, or MSN email account
    http://support.apple.com/kb/ht1694
    Server does not allow relaying email error, fix
    http://appletoolbox.com/2012/01/server-does-not-allow-relaying-email-error-fix/
    Why Does My iPad Say "Cannot Connect to Server"?
    http://www.ehow.co.uk/info_8693415_ipad-say-cannot-connect-server.html
    How to Sync Contacts with Your iPad Using iTunes
    http://www.dummies.com/how-to/content/how-to-sync-contacts-with-your-ipad-using- itunes.html
    iOS: 'Mailbox Locked', account is in use on another device, or prompt to re-enter POP3 password
    http://support.apple.com/kb/ts2621
    eMail Groups - You can use a third party app that many users recommend.
    MailShot -  https://itunes.apple.com/us/app/mailshot-pro-group-email-done/id445996226?mt=8
    Group Email  -  https://itunes.apple.com/us/app/group-email!-mail-client-attachments/id380690305 ?mt=8
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Configuration problems with IMAP e-mail on iOS with a non-standard SSL port.
    http://colinrobbins.me/2013/02/09/configuration-problems-with-imap-e-mail-on-ios -with-a-non-standard-ssl-port/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • Good day my question is , does anyone of you experiencing when making a call with facetime the phone shuts off and restart

    good day my question is , does anyone of you experiencing when making a call with facetime the phone shuts off and restart

    See this veeeeeeeeeery long thread.
    https://discussions.apple.com/thread/3404857
    It's an issue with hundreds of phones.  Some claim it's software related, some hardware, some say it's a mixture of both.
    Some people have had temporary success with quitting the Phone.app / restoring as a new phone / restoring from an iCloud backup / disabling Siri / toggling speakerphone on & off...
    Unfortunately all of the above only been temporary, with the problem recurring again after a few calls, or a few days etc.
    So far the only solution that seems permanent has been to replace the phone.  But even so, it's the luck of the draw to recieve a functional phone, and not another faulty one.
    I'm completely annoyed as there is no Apple Store near me...... and Apple haven't even acknowledged the issue, despite the above thread being 34 pages long, as of writing.

  • Problem opening mail attachments...were opening seamlessly on os 7.0...get an error   Filename Office open XML document/presentation File size   Does anyone have a solution? Please help.

    problem opening mail attachments...were opening seamlessly on os 7.0...get an error
    Filename
    Office open XML document/presentation
    File size
    Does anyone have a solution? Please help.

    Hi Charlotte,
    You don't say what your version of Windows you have. Assuming XP, go to Start | Run, type DXDIAG and click OK. Click the Sound tab and run the tests to eliminate a hardware problem first of all. If you don't hear anything, check your cables first of all. Also make sure "Mute" isn't checkmarked in your sound setup. You'll find that in Windows Control Panel.
    Which browser do you use? If you have Firefox 4, sign up to the HTML5 trial @ http://www.youtube.com/html5
    HTML5 is the latest video standard and doesn't require Flash player. Google is in the process of converting all its files to work with the new format. It may solve you problem. If you don't have Firefox 4, you can get it from here: http://www.mozilla.com/en-US/firefox/fx/
    IE8 doesn't support HTML5.
    To clean out your temp files, go to Start | Run, type: CLEANMGR and click OK. Click OK again to start the utility. Tick all the boxes except "Compress old files" because the latter takes too long, and then click OK. You can run this utility any time you wish by the way.
    The above steps will hopefully fix your problem. If not, post here again please.

  • Hi. Does anyone know what video editing software is compatible with my MacBook - version 10.6.3? I am looking to edit films and already have Final Cut Pro, but am looking for something a little more basic and easier to use. Thanks. Vicki

    Hi. Does anyone know what video editing software is compatible with my MacBook - version 10.6.3? I am looking to edit films and already have Final Cut Pro, but am looking for something a little more basic and easier to use. Thanks. Vicki

    Hi Cereskit
    Thanks again for the message. I've done the updates and have the App Store on my desktop. I went into it and searched for imovie but couldn't find the basic imovie, which I presume is what I'd need for editing?, rather than imovie 11 for £10.49, which is for making trailers, it seems. Also, were you saying that imovie would be free?
    Vicki

  • I have a iPhone 5 only had it 5 months on the screen it as *** up wiv a padlock wiv a circle around it.. Does anyone no wot this is and how do u remove it? I've been through my phone but can't find anything.. Thanks

    I have a iPhone 5 only had it 5 months on the screen it as *** up wiv a padlock wiv a circle around it.. Does anyone no wot this is and how do u remove it? I've been through my phone but can't find anything.. Thanks

    Do you mean Screen Rotation Lock:
    This keeps your screen from rotating.
    iOS: Screen does not rotate - Support - Apple

  • HT1349 The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only t

    The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only time it works correct. Bill. [email protected]  708 752  3667 

    http://lifehacker.com/5852948/what-to-do-if-youve-forgotten-your-iphones-passcod e

  • I have a macbook from early 2008, and when I sign onto safari I get an error message for fast browser search plugin.  After that error comes up my computer freezes and I have to force it to shut down.  Does anyone know what that means and how I can fix it

    I have a macbook from early 2008, and when I sign onto safari I get an error message for fast browser search plugin.  After that error comes up my computer freezes and I have to force it to shut down.  Does anyone know what that means and how I can fix it?

    Means you have an incompatible Safari extension installed. Look in the /Home/Library/Safari/Extensions/ folder for the offending plug-in and delete it.

Maybe you are looking for