Skip to content

Instantly share code, notes, and snippets.

@mallain
Created August 9, 2010 13:52
Show Gist options
  • Save mallain/515438 to your computer and use it in GitHub Desktop.
Save mallain/515438 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"1";"2000-01-01 10:00:00"
"2";"2000-02-01 10:00:00"
"3";"2000-03-01 10:00:00"
"4";"2000-04-01 10:00:00"
"5";"2000-05-01 10:00:00"
"6";"2000-06-01 10:00:00"
"7";"2000-07-01 10:00:00"
"8";"2000-08-01 10:00:00"
"9";"2000-09-01 10:00:00"
"10";"2000-10-01 10:00:00"
"11";"2000-11-01 10:00:00"
"12";"2000-12-01 10:00:00"
"13";"2001-01-01 10:00:00"
"14";"2001-02-01 10:00:00"
"15";"2001-03-01 10:00:00"
"16";"2001-04-01 10:00:00"
"17";"2001-05-01 10:00:00"
"18";"2001-06-01 10:00:00"
"19";"2001-07-01 10:00:00"
"20";"2001-08-01 10:00:00"
"21";"2001-09-01 10:00:00"
"22";"2001-10-01 10:00:00"
"23";"2001-11-01 10:00:00"
"24";"2001-12-01 10:00:00"
"25";"2002-01-01 10:00:00"
"26";"2002-02-01 10:00:00"
"27";"2002-03-01 10:00:00"
"28";"2002-04-01 10:00:00"
"29";"2002-05-01 10:00:00"
"30";"2002-06-01 10:00:00"
-- Use database
USE pabd_development;
-- Suppression de la procedure si elle existe
DROP FUNCTION IF EXISTS halfyear;
-- Changement du parametre "delimiter" pour creer la procedure
DELIMITER $$
-- Creation de la procedure halfyear
-- Retourne la position semestre 1 ou 2 du datetime en parametre (Integer)
CREATE FUNCTION halfyear(datetime_var DATETIME) RETURNS INT
BEGIN
/* Initialisation de variables locales */
DECLARE return_value INT DEFAULT 1;
DECLARE quarter_value INT;
/* Recuperation du quarter du datetime */
SELECT quarter(datetime_var) INTO quarter_value;
/* Si la position trimestre est superieure a 2*/
IF quarter_value > 2 THEN
/* Nous sommes au semestre 2*/
SET return_value = 2;
END IF;
/* Retour de la valeur semestre */
RETURN return_value;
END;
$$
-- Remise a l etat initial du parametre "delimiter"
DELIMITER ;
SELECT id,feedback_time, year(feedback_time), halfyear(feedback_time), quarter(feedback_time), month(feedback_time) FROM `feedbacks` WHERE 1
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"1";"2000-01-01 10:00:00";"2000";"1";"1";"1"
"2";"2000-02-01 10:00:00";"2000";"1";"1";"2"
"3";"2000-03-01 10:00:00";"2000";"1";"1";"3"
"4";"2000-04-01 10:00:00";"2000";"1";"2";"4"
"5";"2000-05-01 10:00:00";"2000";"1";"2";"5"
"6";"2000-06-01 10:00:00";"2000";"1";"2";"6"
"7";"2000-07-01 10:00:00";"2000";"2";"3";"7"
"8";"2000-08-01 10:00:00";"2000";"2";"3";"8"
"9";"2000-09-01 10:00:00";"2000";"2";"3";"9"
"10";"2000-10-01 10:00:00";"2000";"2";"4";"10"
"11";"2000-11-01 10:00:00";"2000";"2";"4";"11"
"12";"2000-12-01 10:00:00";"2000";"2";"4";"12"
"13";"2001-01-01 10:00:00";"2001";"1";"1";"1"
"14";"2001-02-01 10:00:00";"2001";"1";"1";"2"
"15";"2001-03-01 10:00:00";"2001";"1";"1";"3"
"16";"2001-04-01 10:00:00";"2001";"1";"2";"4"
"17";"2001-05-01 10:00:00";"2001";"1";"2";"5"
"18";"2001-06-01 10:00:00";"2001";"1";"2";"6"
"19";"2001-07-01 10:00:00";"2001";"2";"3";"7"
"20";"2001-08-01 10:00:00";"2001";"2";"3";"8"
"21";"2001-09-01 10:00:00";"2001";"2";"3";"9"
"22";"2001-10-01 10:00:00";"2001";"2";"4";"10"
"23";"2001-11-01 10:00:00";"2001";"2";"4";"11"
"24";"2001-12-01 10:00:00";"2001";"2";"4";"12"
"25";"2002-01-01 10:00:00";"2002";"1";"1";"1"
"26";"2002-02-01 10:00:00";"2002";"1";"1";"2"
"27";"2002-03-01 10:00:00";"2002";"1";"1";"3"
"28";"2002-04-01 10:00:00";"2002";"1";"2";"4"
"29";"2002-05-01 10:00:00";"2002";"1";"2";"5"
"30";"2002-06-01 10:00:00";"2002";"1";"2";"6"
@mallain
Copy link
Author

mallain commented Aug 9, 2010

Création d'une fonction MySQL pour calculer la position "semestre" d'une valeur en Datetime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment