Обсуждение: ORDER the result of a query by date

Поиск
Список
Период
Сортировка

ORDER the result of a query by date

От
andres javier garcia garcia
Дата:
Hello;
I've got the result of a query that appears as:cod_variable | cod_station | year | month | day | rain
---------------------+-------------------+--------+----------+------+------30201           | 7237           | 1953 |
   1 |   1 |    230201           | 7237           | 1953 |        2 |   1 |    530201           | 7237           | 1953
|       3 |   1 |    030201           | 7237           | 1953 |        4 |   1 |   -3
 
.....

(Of course, thanks to Stephan Szabo for the method to obtain this from my 
strange source data. I didn't think this was possible.)

After have done this query I've realized that I need the data to be ordered 
by date. Do you have any suggestion?

Best regards
----------
Javier


Re: ORDER the result of a query by date

От
Achilleus Mantzios
Дата:
On Thu, 24 Oct 2002, andres javier garcia garcia wrote:

> Hello;
> I've got the result of a query that appears as:
>  cod_variable | cod_station | year | month | day | rain
> ---------------------+-------------------+--------+----------+------+------
>  30201           | 7237           | 1953 |        1 |   1 |    2
>  30201           | 7237           | 1953 |        2 |   1 |    5
>  30201           | 7237           | 1953 |        3 |   1 |    0
>  30201           | 7237           | 1953 |        4 |   1 |   -3
> .....
>
> (Of course, thanks to Stephan Szabo for the method to obtain this from my
> strange source data. I didn't think this was possible.)
>
> After have done this query I've realized that I need the data to be ordered
> by date. Do you have any suggestion?

select <your cols>,year,month,day from <your table> order by
year,month,day.

Also take a look at date,timestamp data types.
Note that you can process your initial "strange" source
using tools as awk,perl,sh,C programs to format
your datasets in sql insert statements or
copy format.

>
> Best regards
> ----------
> Javier
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

==================================================================
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com       mantzios@softlab.ece.ntua.gr



Re: ORDER the result of a query by date

От
"Henshall, Stuart - Design & Print"
Дата:
<p><font size="2">andres javier garcia garcia wrote:</font><br /><font size="2">> Hello;</font><br /><font
size="2">>I've got the result of a query that appears as:</font><br /><font size="2">>  cod_variable |
cod_station| year | month | day | rain</font><br /><font size="2">>
---------------------+-------------------+--------+----------+</font><br/><font size="2">> ------+------</font><br
/><fontsize="2">>  30201           | 7237           | 1953 |        1 |   1 |    2</font><br /><font size="2">> 
30201          | 7237           | 1953 |        2 |   1 |    5</font><br /><font size="2">>  30201           |
7237          | 1953 |        3 |   1 |    0</font><br /><font size="2">>  30201           | 7237           | 1953
|       4 |   1 |   -3 .....</font><br /><font size="2">> </font><br /><font size="2">> (Of course, thanks to
StephanSzabo for the method to obtain this</font><br /><font size="2">> from my strange source data. I didn't think
thiswas possible.)</font><br /><font size="2">> </font><br /><font size="2">> After have done this query I've
realizedthat I need the data to be</font><br /><font size="2">> ordered by date. Do you have any
suggestion?</font><br/><font size="2">> </font><br /><font size="2">> Best regards</font><br /><font
size="2">>----------</font><br /><font size="2">> Javier</font><br /><font size="2">> </font><br /><font
size="2"> ORDERBY year,month,day should do it.</font><br /><font size="2">hth,</font><br /><font size="2">-
Stuart</font>