MySQL Forums
Forum List  »  French

Re: SQL COUNT et DISTINCT
Posted by: Jean Molliné
Date: December 20, 2018 04:04AM

Pour l'utilisation de SUBSTRING, une première approche consiste à jeter un coup d’œil dans la documentation :
SUBSTRING(str, pos, len)
Ou bien :
SUBSTRING(str FROM pos FOR len)

Si dans une colonne nommée identifiant j'ai un identifiant de la forme AAAAMMJJXXX, je peux créer deux alias, un pour la date, l'autre pour le numéro avec quelque chose comme par exemple :

SELECT
  SUBSTRING(identifiant, 9, 3) AS numero,
  CAST(
    CONCAT(
      SUBSTRING(identifiant, 1, 4),
      '-',
      SUBSTRING(identifiant, 5, 2),
      '-',
      SUBSTRING(identifiant, 7, 2)
    )
  AS DATE) AS datedossier
FROM xxxx.

Si la valeur dans la colonne identifiant est par exemple '20181220123', j'obtiendrai ce résultat :
+--------+-------------+
| numero | datedossier |
+--------+-------------+
| 123    | 2018-12-20  |
+--------+-------------+

______________________________________________________________
Une question bien formulée, c'est un problème bien compris : ça représente déjà les 3/4 de la réponse ;)

Options: ReplyQuote


Subject
Views
Written By
Posted
1627
December 14, 2018 05:38PM
698
December 16, 2018 12:38PM
786
December 16, 2018 01:20PM
712
December 16, 2018 01:47PM
655
December 20, 2018 03:48AM
Re: SQL COUNT et DISTINCT
687
December 20, 2018 04:04AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.