0

In the image, I have two records that have the same payment ID, and I sum everything related to that payment ID but when I try to show it separate items I come across a problem when someone pays the amount that they pay will be stored and I don't know how to hide the duplicates, sorry for little info, but I wanna make paid amount column to show that 600 once and for the next row be empty is that possible by query or its fixed in visual studio

total paid amount

300 600

300 //this cell be empty Query:

 select `payment`.`id_payment` as `Payment ID`,
       `payment`.`doctor_id` as `Doctor ID`,
       `patient_information`.`id_user` as `Code`,
       CONCAT (`patient_information`.`firstname`,
       ' ', `patient_information`.`middlename`,
       ' ',
       `patient_information`.`lastname`) as `Customer`,
       `payment`.`date` as `Date`,
       `bills`.`name` as `Tretment`,
      (COALESCE(SUM(`items`.`sell_price`),0)+sum(`bills`.`price`)) as `Total`,
       `payment`.`amount` as `Paid amount`,
      `payment`.`discount`,
       `payment`.`status` as `Status`,
       COALESCE(sum(items.price),0) as `R.M`,
       (COALESCE(sum(items.sell_price),0)+`bills`.`price`) - sum(items.price)  AS `G.P`
  from (((((`payment` `payment`
  inner join `patient_information`
       `patient_information`
       on (`patient_information`.`id_user` = `payment`.`paitent_id`))
  inner join `paymen_information`
       `paymen_information`
       on (`paymen_information`.`id_payment` = `payment`.`id_payment`))
  inner join `bills` `bills`
       on (`bills`.`id_bill` = `paymen_information`.`id_bill`))
  inner join `bill_information` `bill_information`
       on (`bill_information`.`bills_id` = `bills`.`id_bill`))
  inner join `items` `items`
       on (`items`.`id_item` = `bill_information`.`item_id`))
         WHERE payment.date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) AND CURRENT_DATE()
         GROUP by `payment`.`id_payment`,`bills`.`id_bill`,`paymen_information`.`id`

Sample

6
  • 2
    Please don't force people here to debug screenshots. Post a minimal reproducible example of your data, current code and desired result as text here so people here don't have to re-type your data just to answer your question. Commented Aug 16, 2021 at 12:52
  • At a minimum, post your current query Commented Aug 16, 2021 at 12:53
  • @Kevin i added the Query Commented Aug 16, 2021 at 12:55
  • @Kevin i wanna make paid amount column to show that 600 once and for the next row be empty is that possible by query or its fixed in visual studio Commented Aug 16, 2021 at 12:57
  • you can just add DISTINCT on the Payment ID column as a temporary solution but there should not be duplicate payments with one payment id in your database. Commented Aug 16, 2021 at 13:04

1 Answer 1

0

I don't really understand what you want to achieve, but if Payment ID is your primary key it should be set as Unique to avoid this kind of situations. For cleaning duplicates you can run a DELETE JOIN query like in the next link: https://www.mysqltutorial.org/mysql-delete-duplicate-rows/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.