1. 选择列:
SELECT column1, column2 FROM your_table;
2. 重命名列:
SELECT column1 AS new_name1, column2 AS new_name2 FROM your_table;
3. 计算新列:
SELECT column1, column2, column1 + column2 AS sum_result FROM your_table;
4. 使用聚合函数:
SELECT AVG(column1) AS avg_value FROM your_table;
5. 使用CASE表达式生成新列:
SELECT
column1,
CASE
WHEN column2 > 100 THEN 'High'
WHEN column2 > 50 THEN 'Medium'
ELSE 'Low'
END AS priority
FROM your_table;
6. 使用窗口函数:
SELECT
column1,
AVG(column2) OVER (PARTITION BY column3 ORDER BY column4) AS avg_value
FROM your_table;
7. 连接多个表并选择列:
SELECT
your_table.column1,
another_table.column2
FROM
your_table
JOIN
another_table ON your_table.id = another_table.id;
8. 使用子查询选择列:
SELECT
column1,
(SELECT AVG(column2) FROM another_table WHERE another_table.id = your_table.id) AS avg_value
FROM your_table;
这些列表达式允许你根据需求选择、计算、重命名列,使得查询结果满足特定的业务需求。你可以根据具体的情况组合和调整这些表达式。
转载请注明出处:http://www.zyzy.cn/article/detail/11721/OceanBase