简体   繁体   中英

Different result in SQL fiddle and in MySQL server/PhpMyadmin

This is the sql fiddle : http://sqlfiddle.com/#!2/e6acc/4

And it shows the right result since I want the duplicate entries to be enumerated.

But when I run in on mysql/phpmyadmin, the result is this:

1515    Abdominal
1100    Hep B Inj Fee
40  1-Ligation
40  1-Ligation
900 1-Suturing Fee
900 1-Suturing Fee
900 1-Suturing Fee
900 1-Suturing Fee

It's all 1. I already restarted my pc. and its still the same. Why is that? I just retrieved the csv tables from my mysql to the fiddle.

edit: Ok this is getting weirder. On my front-end, its working when I view other ID's: 在此输入图像描述

But still, when I change the id on my query and enter in on phpmyadmin, it stil shows 1.

I don't have any idea why the SQL Fiddle is different than the actual result, but I managed to make it work for me in PHP. Use the following query:

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

The only thing I changed was line 27 from JOIN (SELECT @curRow:=0) r to JOIN (SELECT @curRow:=0, @prevRow:= '') r

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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