《PostgreSQL自学的艺术》一书;我不明白横向连接是什么意思?

《PostgreSQL自学的艺术》一书;我不明白横向连接是什么意思?,postgresql,Postgresql,我猜在这个标签上很多人买了《PostgreSQL的艺术》一书。这本书的内容就是这个问题的背景。我自学这本书。我遇到了一些问题,所以我写了一封邮件给作者,也在这里问这个问题 第47页: 我完全不明白第27行limit:n是什么意思 我也不知道第34行ss(姓名、唱片ID、计数)对true的意义是什么 我有点明白了。但我仍然不确定是什么造成的 横向连接怎么办 -- name: genre-top-n 2 -- Get the N top tracks by genre 3 select g

我猜在这个标签上很多人买了《PostgreSQL的艺术》一书。这本书的内容就是这个问题的背景。我自学这本书。我遇到了一些问题,所以我写了一封邮件给作者,也在这里问这个问题

第47页:

  • 我完全不明白第27行
    limit:n
    是什么意思

  • 我也不知道第34行
    ss(姓名、唱片ID、计数)对true的意义是什么

  • 我有点明白了。但我仍然不确定是什么造成的 横向连接怎么办

    -- name: genre-top-n
     2 -- Get the N top tracks by genre
     3 select genre.name as genre,
     4 case when length(ss.name) > 15
     5 then substring(ss.name from 1 for 15) || '…'
     6 else ss.name
     7 end as track,
     8 artist.name as artist
     9 from genre
     10 left join lateral
     11 /*
     12 * the lateral left join implements a nested loop over
     13 * the genres and allows to fetch our Top-N tracks per
     Chapter 5 A Small Application | 47
     14 * genre, applying the order by desc limit n clause.
     15 *
     16 * here we choose to weight the tracks by how many
     17 * times they appear in a playlist, so we join against
     18 * the playlisttrack table and count appearances.
     19 */
     20 (
     21 select track.name, track.albumid, count(playlistid)
     22 from track
     23 left join playlisttrack using (trackid)
     24 where track.genreid = genre.genreid
     25 group by track.trackid
     26 order by count desc
     27 limit :n
     28 )
     29 /*
     30 * the join happens in the subquery's where clause, so
     31 * we don't need to add another one at the outer join
     32 * level, hence the "on true" spelling.
     33 */
     34 ss(name, albumid, count) on true
     35 join album using(albumid)
     36 join artist using(artistid)
     37 order by genre.name, ss.count desc;
    
请不要假设任何人手头有任何特定的书籍,并将您的问题保持独立,以便任何人回答。第34行是表格别名: