sql >> Database teknologi >  >> RDS >> Mysql

Forskelligt resultat i SQL violin og i MySQL server/PhpMyadmin

Jeg har ingen idé om, hvorfor SQL Fiddle er anderledes end det faktiske resultat, men det lykkedes mig at få det til at fungere for mig i PHP. Brug følgende forespørgsel:

SELECT
  c.procno,
  CONCAT(CASE WHEN cnt > 1 THEN CONCAT(RN,'-') ELSE '' END, t.Proc) Proc
FROM
  (
    SELECT
      @curRow:=CASE WHEN @prevRow = a.Proc THEN @curRow+1 ELSE 1 END AS rn,
      a.Proc,
      a.Procno,
      @prevRow:=Proc grp
    FROM (    
          SELECT
            `incurredcharges`.`procedure_no` procno,
            `c`.`procedure` proc
          FROM
            incurredcharges
            INNER JOIN (
              SELECT `procedure`, `procedure_no` FROM `charges`
              UNION ALL
              SELECT `confinement`, `procedure_no` FROM `confinement`
              UNION ALL
              SELECT `service`, `procedure_no` FROM `ultrasound`
            ) c ON `incurredcharges`.`procedure_no` = c.`procedure_no`
          WHERE `incurredcharges`.`patient_no` = '34'
          ORDER BY `c`.`procedure`
      ) a 
          JOIN (SELECT @curRow:=0, @prevRow:= '') r
  ) t JOIN
  (
          SELECT
            `incurredcharges`.`procedure_no` procno,
            `c`.`procedure` proc, Count(*) cnt
          FROM
            incurredcharges
            INNER JOIN (
              SELECT `procedure`, `procedure_no` FROM `charges`
              UNION ALL
              SELECT `confinement`, `procedure_no` FROM `confinement`
              UNION ALL
              SELECT `service`, `procedure_no` FROM `ultrasound`
            ) c ON `incurredcharges`.`procedure_no` = c.`procedure_no`
          WHERE `incurredcharges`.`patient_no` = '34'
          GROUP BY `incurredcharges`.`procedure_no`,
            `c`.`procedure`
  ) c ON t.proc = c.proc

Det eneste jeg ændrede var linje 27 fra JOIN (SELECT @curRow:=0) r for at JOIN (SELECT @curRow:=0, @prevRow:= '') r




  1. Skift en partition ud i SQL Server (T-SQL)

  2. Brug Firebase DB med lokal DB

  3. Postgres er den fedeste database – Årsag #1:Udviklere elsker det!

  4. Sådan gemmer du et MySQL-forespørgselsresultat i en .CSV-fil