Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

Applying a rule through querys?

Discussion in 'Information Technology' started by Stefan, Jul 28, 2006.

  1. Stefan

    Stefan
    Expand Collapse
    Guest

    Hi,

    I've got a list with people who would be buying a house.

    The people who lives in the same town off the project gets a priority-rule.

    The rule is that these people can shift 50% forwards but the other ones can
    move backward only ones.

    Example:

    Nr Name Priority
    1 Pers1 yes
    2 Pers2 no
    3 Pers3 no
    4 Pers4 yes
    5 Pers5 yes


    After applying the rule:

    Nr Name Priority
    1 1 Pers1 yes
    2 4 Pers4 yes
    3 2 Pers2 no
    4 5 Pers5 yes
    5 3 Pers3 no

    Who can help me with this.
    --
    Stefan
     
  2. Loading...

    Similar Threads Forum Date
    Sikhism Brahmanical Way of Applying Gurbani Book Reviews & Editorials Jun 2, 2010
    Extract: The untold history of Sikh Rule under Ranjit Singh Ji in Lahore Sikh Personalities May 28, 2014
    Canada FIFA Rules in Favor of Religious Headgear Breaking News Mar 2, 2014
    USA Pentagon to relax rules on personal religious wear — including beards, turbans Breaking News Jan 23, 2014
    Sikh Coalition Sikh American Organizations Stand with Gurbaksh Singh on 36th Day of His Hunger Strike; Demand Rule Sikh Organisations Dec 21, 2013

  3. Jamie Collins

    Jamie Collins
    Expand Collapse
    Guest

    Stefan wrote:
    > I've got a list with people who would be buying a house.
    >
    > The people who lives in the same town off the project gets a priority-rule.
    >
    > The rule is that these people can shift 50% forwards but the other ones can
    > move backward only ones.
    >
    > Example:
    >
    > Nr Name Priority
    > 1 Pers1 yes
    > 2 Pers2 no
    > 3 Pers3 no
    > 4 Pers4 yes
    > 5 Pers5 yes
    >
    >
    > After applying the rule:
    >
    > Nr Name Priority
    > 1 1 Pers1 yes
    > 2 4 Pers4 yes
    > 3 2 Pers2 no
    > 4 5 Pers5 yes
    > 5 3 Pers3 no


    A quick stab (the really small DECIMAL value is to break ties in favour
    of Priority = 'Y'):

    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1;

    To get the new Nr i.e. an INTEGER rank rather than a DECIMAL, just plug
    the resultset back in (oh for CTE's in Jet <g>):

    SELECT DT1.Nr, DT1.Name, DT1.Priority,
    (
    SELECT COUNT(*)
    FROM
    (
    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1
    ) AS DT2
    WHERE DT2.new_rank <= DT1.new_rank
    ) AS new_Nr
    FROM
    (
    SELECT H1.Nr, H1.Name, H1.Priority,
    IIF(H1.Priority = 'Y',
    H1.Nr * 0.5,
    H1.Nr + 0.00000000000000000001) AS new_rank
    FROM Housing AS H1
    ) AS DT1;

    Jamie.

    --
     
  4. Stefan

    Stefan
    Expand Collapse
    Guest

    >
    > Stefan wrote:
    > > I've got a list with people who would be buying a house.
    > >
    > > The people who lives in the same town off the project gets a priority-rule.
    > >
    > > The rule is that these people can shift 50% forwards but the other ones can
    > > move backward only ones.
    > >
    > > Example:
    > >
    > > Nr Name Priority
    > > 1 Pers1 yes
    > > 2 Pers2 no
    > > 3 Pers3 no
    > > 4 Pers4 yes
    > > 5 Pers5 yes
    > >
    > >
    > > After applying the rule:
    > >
    > > Nr Name Priority
    > > 1 1 Pers1 yes
    > > 2 4 Pers4 yes
    > > 3 2 Pers2 no
    > > 4 5 Pers5 yes
    > > 5 3 Pers3 no

    >
    > A quick stab (the really small DECIMAL value is to break ties in favour
    > of Priority = 'Y'):
    >
    > SELECT H1.Nr, H1.Name, H1.Priority,
    > IIF(H1.Priority = 'Y',
    > H1.Nr * 0.5,
    > H1.Nr + 0.00000000000000000001) AS new_rank
    > FROM Housing AS H1;
    >


    Thanks,

    This code works fine.
    Monday i can compare this result with the manual result of my boss. On a
    first glimp it looks great.


    --
    Stefan
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page