查询数据:
选择所有列的所有行:
SELECT * FROM table_name;
选择指定列的所有行:
SELECT column1, column2 FROM table_name;
条件查询:
SELECT * FROM table_name WHERE condition;
排序查询结果:
SELECT * FROM table_name ORDER BY column1 ASC;
限制查询结果行数:
SELECT * FROM table_name LIMIT 10;
子查询:
标量子查询:
SELECT column1, (SELECT MAX(column2) FROM table2) AS max_value FROM table1;
行子查询:
SELECT column1 FROM table1 WHERE column2 IN (SELECT column2 FROM table2);
表子查询:
SELECT * FROM (SELECT column1, column2 FROM table1) AS subquery;
连接查询:
INNER JOIN:
SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;
LEFT JOIN(或 LEFT OUTER JOIN):
SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;
RIGHT JOIN(或 RIGHT OUTER JOIN):
SELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;
FULL JOIN(或 FULL OUTER JOIN):
SELECT * FROM table1 FULL JOIN table2 ON table1.column = table2.column;
集合操作:
UNION:
SELECT column1 FROM table1
UNION
SELECT column1 FROM table2;
UNION ALL:
SELECT column1 FROM table1
UNION ALL
SELECT column1 FROM table2;
INTERSECT:
SELECT column1 FROM table1
INTERSECT
SELECT column1 FROM table2;
EXCEPT(或 MINUS):
SELECT column1 FROM table1
EXCEPT
SELECT column1 FROM table2;
这些是一些基本的OceanBase SQL语句,用于执行常见的数据库操作。实际使用时,可以根据具体的业务需求编写更复杂的SQL语句。在编写SQL语句时,确保语法正确、逻辑清晰,并考虑性能优化的问题。
转载请注明出处:http://www.zyzy.cn/article/detail/11497/OceanBase