开始使用免费开始使用

更改字符串数据的大小写

现在,您将使用 filmcategory 表,通过将类别的 name 与影片的 title 连接,创建一个名为 film_category 的新字段。您还将使用视频中介绍的函数来格式化结果,改变查询中所选字段的大小写;例如,INITCAP() 函数可以将字符串转换为标题格式。

本练习是课程的一部分

在 PostgreSQL 中使用函数处理数据

查看课程

练习说明

  • 将影片类别的 name 转换为大写。
  • 将影片 title 中每个单词的首字母转换为大写。
  • 将转换后的类别 name 与影片 title 用冒号连接。
  • description 列转换为小写。

交互式实操练习

通过完成这段示例代码来试试这个练习。

SELECT 
  -- Concatenate the category name to coverted to uppercase
  -- to the film title converted to title case
  ___(___)  || ': ' || ___(___) AS film_category, 
  -- Convert the description column to lowercase
  ___(___) AS description
FROM 
  film AS f 
  INNER JOIN film_category AS fc 
  	ON f.film_id = fc.film_id 
  INNER JOIN category AS c 
  	ON fc.category_id = c.category_id;
编辑并运行代码