[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 875
  • Last Modified:

SQL FIFO Algorithm

I got stuck with a request like this:

Table 1: Input
ID(Identity)           Number           Weight            Kg/Bar(Weight/Number)
1                           2                       20                     10                        
2                           3                       45                      15
3                           5                       50                      10

Table 2: Output
Number                    Weight
  4                               50 (= 10*2 + 15*2)
  6                               65 (= 15*1 + 10*5)

Please help me how to sovle this problem.
3 Solutions
can you explain what exactly you want in some detail
can you describe the problem in more details, because I can't understand the question?
Chris MConsulting - Technology ServicesCommented:
JameMech, please tell us what is puzzling you so that it gets resolved.

In case you're using ID to trace what comes in first, ensure that your query has an "order by ID asc" clause.
NB: For an identity column, the seed and increment define the pattern of populating the column.

Assuming the column was created with properties like IDENTITY(1:1) then the order by clause to trace first in first out will be ID ASC and the lower IDs will be the first ones to get returned.
JameMeckAuthor Commented:
Thanks! I solved by myself.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now