0

I have one column like from query SELECT * FROM Score_TABLE and it returns a result like this:

Score
-----
  78
 712

Now I have to display it with query like this:

Score   Score2
---------------
  78       712

Points is dynamic.

select 
    a.Score 
from 
    (select 
         a.Score 
     from
         (select 
              concat(sum(s.bat_run), '-', 
                     (select count(s.out_type) from status s 
                      where s.out_type = 'out' 
                        and s.match_id = 77)) Score 
          from 
              status s 
          where 
              s.match_id = 77 
          group by 
              s.toss) a 
     where 
         a.Score = Score) a 
where 
    a.Score = Score

Result:

Score    Score2
---------------
 12        42
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kamran ijaz
  • 105
  • 1
  • 4
  • 14
  • How many rows do you expect to be returned by `SELECT * FROM Score_TABLE`? – Pavel Smirnov Apr 11 '19 at 17:35
  • 1
    Why are your queries so nested? They are a lot more complicated than `SELECT * FROM Score_TABLE`. Also, how does the exact same query give two different scores? Perhaps they aren't the same - the layout makes them very hard to read. – APC Apr 11 '19 at 17:37
  • 2
    Also, which database are you using? `[MySQL]` and `[oracle]` are two different databases with different syntaxes, albeit owned by the same corporation. Please don't tag your question with multiple database labels just to attract more eyeballs to your question. You're simply wasting the time of people who post solution you can't use. – APC Apr 11 '19 at 17:40
  • ... and the results are not compatible with the query( there are two columns(`score` and `score2`) returning in the results, but there's one column `score` returning from the query ) – Barbaros Özhan Apr 11 '19 at 17:40
  • You shouldn't be using the same alias `a` multiple times ...... – marc_s Apr 11 '19 at 18:12

2 Answers2

0

this will do :

   SELECT GROUP_CONCAT(score)
   FROM status 
   GROUP BY score;
Nikhil S
  • 3,786
  • 4
  • 18
  • 32
  • Result is Showing Like this after executing this query [BLOB - 3 B] [BLOB - 3 B] – kamran ijaz Apr 11 '19 at 17:54
  • [BLOB - 3 B] [BLOB - 3 B] whats that?? – Nikhil S Apr 11 '19 at 18:16
  • 2
    Hi! While this may be a solution to the question, code only answers are generally discouraged on SO. Please take some time to edit your response with an explanation as to why this is a solution as it will help OP and future visitors of the site. – d_kennetz Apr 11 '19 at 19:23
0

I could not understand your question properly but i think you need to "PIVOT"

this may help you Convert Rows to columns using 'Pivot' in SQL Server