Re: [SQL] Confused about writing this stored procedure/method.

2011-08-24 Thread Tim Landscheidt
(anonymous) wrote:

> [...]
> I intend pass the number of the month(say 1 for January , 2 for February
> etc>) as the parameter to this method and return a number that corresponds
> to the index of the month in the new order , say I pass 8 for August , I
> return 11 , in order to get the  index of August in he financial year
> calendar somewhat like this
> [...]

You don't need any function for that, just use "ORDER BY
Month < 4, Month".

Tim


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] need magic to shuffle some numbers

2011-08-24 Thread Tim Landscheidt
(anonymous) wrote:

> there is a table that has among others a integer primary key
> "id" and another integer column "prio" as well as an integer
> "group_id".

> I'd like to invert the values of the prio-column for one of the groups.
> The prio numbers start with 3 and there are 1159 different
> prios in this group.
> At least every value appeares only once.   :)

> Is there an elegant way to switch the prio values around so
> that every record with the first prio gehts the last and
> vice versa?
> Then the records with the second smallest prio get the
> second-to-last biggest value and v.v.

If you just want to reverse the priorities:

| UPDATE TestTable
|   SET prio = (SELECT MIN(prio) FROM TestTable WHERE group_id = 'testgroup') +
|  (SELECT MAX(prio) FROM TestTable WHERE group_id = 'testgroup') -
|  prio
|   WHERE group_id = 'testgroup';

Tim


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql