How to combine this rows?

Elaya Raja 96 Reputation points

How to achieve this using Mysql

Thanks in advance

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
712 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. Christopher Geckert 91 Reputation points

    You could try to write a CTEs for each column with the Distinct _ReportId and Field. Then join these on cte._ReportId = _ReportID

  2. Erland Sommarskog 100.9K Reputation points MVP

    Beside the correct tag azure-mysql-database, you have tagged your question with two SQL Server tags, which I why I see your question. SQL Server and MySQL are two different products, and query that runs on SQL Server may not run on MySQL and vice versa.)

    However, there are still a few things I like to comment. First off all, when asking for help like this, it is a lot better to share data as CREATE TABLE statements for your table and INSERT statements for the data. We cannot copy and paste from images.

    Next, the problem does not seem solvable. You have a number of rows you want to consolidate into two. The problem is, how do we know that Low-grease auto-level goes together with Auto-Grease All Level OK and Number = 9? If you say "because they all come first in a pair", let me remind you that a table by definition is a unordered set of data. So unless there is something that encodes the order on every row, what you ask for is not possible.

    Then again, from where did you get this data? Somehow, this seems to me like the result of a previous query. Maybe you went wrong at a previous step.

    0 comments No comments