Created
April 23, 2016 19:06
-
-
Save sebastianwebber/89d8fa8257c8c41dd5174ba04c3040b9 to your computer and use it in GitHub Desktop.
exemplo de trabalhar com dias da semana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sebastian=# CREATE TABLE notas (id serial primary key, ano smallint, semana smallint, nota numeric(5,2)); | |
| CREATE TABLE | |
| sebastian=# INSERT into notas (ano, semana, nota) VALUES(2016, 2, 83.7); | |
| INSERT 0 1 | |
| sebastian=# SELECT | |
| sebastian-# (ano || '-01-01')::DATE + (semana ||' weeks')::INTERVAL AS data_inicial, | |
| sebastian-# nota | |
| sebastian-# FROM notas; | |
| data_inicial | nota | |
| ---------------------+------- | |
| 2016-01-15 00:00:00 | 83.70 | |
| (1 row) | |
| sebastian=# INSERT into notas (ano, semana, nota) VALUES(2016, 45, 0.7); | |
| INSERT 0 1 | |
| sebastian=# SELECT | |
| (ano || '-01-01')::DATE + (semana ||' weeks')::INTERVAL AS data_inicial, | |
| nota | |
| FROM notas; | |
| data_inicial | nota | |
| ---------------------+------- | |
| 2016-01-15 00:00:00 | 83.70 | |
| 2016-11-11 00:00:00 | 0.70 | |
| (2 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment