Pick until enough

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • * Tong *

    #1

    Pick until enough

    [Note] this question is cross-posted to 3 unrelated ngs. Please followup
    only to 1.

    Hi,

    How can I do this:
    select g_name from goods order by g_priority where sum(g_value) < 500

    I.e., I want to orderly pick from table goods so that the total picked
    value is less than a defined value.

    Certainly the above sql won't work (tested under mysql). How can I do it?
    Thanks!

    --
    Tong (remove underscore(s) to reply)
    *niX Power Tools Project: http://xpt.sourceforge.net/
    - All free contribution & collection
  • Serge Rielau

    #2
    Re: Pick until enough

    * Tong * wrote:[color=blue]
    > [Note] this question is cross-posted to 3 unrelated ngs. Please followup
    > only to 1.
    >
    > Hi,
    >
    > How can I do this:
    > select g_name from goods order by g_priority where sum(g_value) < 500
    >
    > I.e., I want to orderly pick from table goods so that the total picked
    > value is less than a defined value.
    >
    > Certainly the above sql won't work (tested under mysql). How can I do it?
    > Thanks!
    >[/color]
    select g_name from
    (select sum(g_value) over(order by g_priority) as running_sum,
    g_name from goods) as g where running_sum < 500

    Cheers
    Serge


    --
    Serge Rielau
    DB2 SQL Compiler Development
    IBM Toronto Lab

    Comment

    Working...