gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
4.9KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>7.1. Overview</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="queries.html" title="Chapter 7. Queries" /><link rel="next" href="queries-table-expressions.html" title="7.2. Table Expressions" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">7.1. Overview</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="queries.html" title="Chapter 7. Queries">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="queries.html" title="Chapter 7. Queries">Up</a></td><th width="60%" align="center">Chapter 7. Queries</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="queries-table-expressions.html" title="7.2. Table Expressions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="QUERIES-OVERVIEW"><div class="titlepage"><div><div><h2 class="title" style="clear: both">7.1. Overview</h2></div></div></div><p>
  3. The process of retrieving or the command to retrieve data from a
  4. database is called a <em class="firstterm">query</em>. In SQL the
  5. <a class="xref" href="sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> command is
  6. used to specify queries. The general syntax of the
  7. <code class="command">SELECT</code> command is
  8. </p><pre class="synopsis">
  9. [<span class="optional">WITH <em class="replaceable"><code>with_queries</code></em></span>] SELECT <em class="replaceable"><code>select_list</code></em> FROM <em class="replaceable"><code>table_expression</code></em> [<span class="optional"><em class="replaceable"><code>sort_specification</code></em></span>]
  10. </pre><p>
  11. The following sections describe the details of the select list, the
  12. table expression, and the sort specification. <code class="literal">WITH</code>
  13. queries are treated last since they are an advanced feature.
  14. </p><p>
  15. A simple kind of query has the form:
  16. </p><pre class="programlisting">
  17. SELECT * FROM table1;
  18. </pre><p>
  19. Assuming that there is a table called <code class="literal">table1</code>,
  20. this command would retrieve all rows and all user-defined columns from
  21. <code class="literal">table1</code>. (The method of retrieval depends on the
  22. client application. For example, the
  23. <span class="application">psql</span> program will display an ASCII-art
  24. table on the screen, while client libraries will offer functions to
  25. extract individual values from the query result.) The select list
  26. specification <code class="literal">*</code> means all columns that the table
  27. expression happens to provide. A select list can also select a
  28. subset of the available columns or make calculations using the
  29. columns. For example, if
  30. <code class="literal">table1</code> has columns named <code class="literal">a</code>,
  31. <code class="literal">b</code>, and <code class="literal">c</code> (and perhaps others) you can make
  32. the following query:
  33. </p><pre class="programlisting">
  34. SELECT a, b + c FROM table1;
  35. </pre><p>
  36. (assuming that <code class="literal">b</code> and <code class="literal">c</code> are of a numerical
  37. data type).
  38. See <a class="xref" href="queries-select-lists.html" title="7.3. Select Lists">Section 7.3</a> for more details.
  39. </p><p>
  40. <code class="literal">FROM table1</code> is a simple kind of
  41. table expression: it reads just one table. In general, table
  42. expressions can be complex constructs of base tables, joins, and
  43. subqueries. But you can also omit the table expression entirely and
  44. use the <code class="command">SELECT</code> command as a calculator:
  45. </p><pre class="programlisting">
  46. SELECT 3 * 4;
  47. </pre><p>
  48. This is more useful if the expressions in the select list return
  49. varying results. For example, you could call a function this way:
  50. </p><pre class="programlisting">
  51. SELECT random();
  52. </pre><p>
  53. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="queries.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="queries.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="queries-table-expressions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Queries </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 7.2. Table Expressions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1