简体   繁体   English

查找具有存储过程的学期

[英]Find the semester with a stored procedure

I have a query : 我有一个查询:

SELECT * FROM `commande`:

id   datecreation            motif          tva    numero   periode
1   27/02/2017 16:16    Achat marchandise   NULL    C001    NULL
9   28/03/2017 14:43    Achat marchandise   NULL    C002    NULL
10  28/03/2017 14:47    Achat marchandise   NULL    C003    NULL
11  28/04/2017 14:53    Achat marchandise   NULL    C004    NULL
12  28/04/2017 14:57    Achat marchandise   NULL    C005    NULL
13  28/05/2017 15:00    Achat marchandise   NULL    C006    NULL
14  28/05/2017 15:36    Achat marchandise   NULL    C007    NULL
15  28/05/2017 16:58    Achat marchandise   NULL    C008    NULL
16  28/05/2017 17:11    Achat marchandise   NULL    C009    NULL

I want to create a stored procedure to update a column "periode" according to "datecreation" month,"periode" column is a semester number, 我想创建一个存储过程来根据“ datecreation”月份更新“ periode”列,“ periode”列是一个学期号,

for example: 例如:

 if month(datecreation)=4 then periode = 2 

 if month(datecreation)=3 then periode = 1

 if month(datecreation)=5 then periode = 2

How I can do this?Thanks 我该怎么办?

As I mentioned in comment semester system divides year in 2 parts. 正如我在评论学期中提到的,学期制将年份分为两部分。 In that case month 1 - 6 are semester 1 and month 7 - 12 are semester 2. You can achieve it like below 在这种情况下,第1-6个月是第1学期,而第7-12个月是第2学期。您可以像下面这样实现

update commande
set periode =
(floor(month(datecreation)/6) + 1 ); 

If you want month 3 as 1 and month 4 and 5 as 2 , then you are talking about quarter system where year is divided in 4 parts. 如果您希望第3个月为1 ,第4个月和第5个月为2 ,那么您正在谈论的是季度制,其中将年份分为4部分。 In that case use 在那种情况下使用

update commande
set periode =
(floor(month(datecreation)/4) + 1 ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM