Constructing a string out of several records with 2 columns

前端 未结 1 602
青春惊慌失措
青春惊慌失措 2021-01-23 03:36

I have prepared a simple SQL Fiddle for my question -

In a word game written in Pl/pgSQL for PostgreSQL 10.2 player moves are stored in the table:

CREATE         


        
相关标签:
1条回答
  • 2021-01-23 04:07

    Use FORMAT (as described in the manual) to format your string before aggregation:

    SELECT STRING_AGG(FORMAT('%s (%s)', word, score), ', ') FROM words_scores WHERE mid=230;
    

    Here's the updated SQL Fiddle.

    0 讨论(0)
提交回复
热议问题