同步操作将从 IvorySQL/IvorySQL 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
------------------------------------------------------------------------------- basics.sql--- Tutorial on the basics (table creation and data manipulation)------ src/tutorial/basics.source------------------------------------------------------------------------------------------------------------ Creating a New Table:-- A CREATE TABLE is used to create base tables. PostgreSQL has-- its own set of built-in types. (Note that SQL is case--- insensitive.)-----------------------------CREATE TABLE weather (city varchar(80),temp_lo int, -- low temperaturetemp_hi int, -- high temperatureprcp real, -- precipitationdate date);CREATE TABLE cities (name varchar(80),location point);------------------------------- Populating a Table With Rows:-- An INSERT statement is used to insert a new row into a table. There-- are several ways you can specify what columns the data should go to.------------------------------- 1. The simplest case is when the list of value correspond to the order of-- the columns specified in CREATE TABLE.INSERT INTO weatherVALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');INSERT INTO citiesVALUES ('San Francisco', '(-194.0, 53.0)');-- 2. You can also specify what column the values correspond to. (The columns-- can be specified in any order. You may also omit any number of columns,-- e.g., unknown precipitation below.INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');INSERT INTO weather (date, city, temp_hi, temp_lo)VALUES ('1994-11-29', 'Hayward', 54, 37);------------------------------- Querying a Table:-- A SELECT statement is used for retrieving data. The basic syntax is-- SELECT columns FROM tables WHERE predicates.------------------------------- A simple one would be:SELECT * FROM weather;-- You may also specify expressions in the target list. (The 'AS column'-- specifies the column name of the result. It is optional.)SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date FROM weather;-- If you want to retrieve rows that satisfy certain condition (i.e., a-- restriction), specify the condition in WHERE. The following retrieves-- the weather of San Francisco on rainy days.SELECT *FROM weatherWHERE city = 'San Francisco'AND prcp > 0.0;-- Here is a more complicated one. Duplicates are removed when DISTINCT is-- specified. ORDER BY specifies the column to sort on. (Just to make sure the-- following won't confuse you, DISTINCT and ORDER BY can be used separately.)SELECT DISTINCT cityFROM weatherORDER BY city;------------------------------- Joins Between Tables:-- queries can access multiple tables at once or access the same table-- in such a way that multiple instances of the table are being processed-- at the same time.------------------------------- The following joins the weather table and the cities table.SELECT * FROM weather JOIN cities ON city = name;-- This prevents a duplicate city name column:SELECT city, temp_lo, temp_hi, prcp, date, locationFROM weather JOIN cities ON city = name;-- since the column names are all different, we don't have to specify the-- table name. If you want to be clear, you can do the following. They give-- identical results, of course.SELECT weather.city, weather.temp_lo, weather.temp_hi, weather.prcp, weather.date, cities.locationFROM weather JOIN cities ON weather.city = cities.name;-- Old join syntaxSELECT *FROM weather, citiesWHERE city = name;-- Outer joinSELECT *FROM weather LEFT OUTER JOIN cities ON weather.city = cities.name;-- Suppose we want to find all the records that are in the temperature range-- of other records. w1 and w2 are aliases for weather.SELECT w1.city, w1.temp_lo, w1.temp_hi,w2.city, w2.temp_lo, w2.temp_hiFROM weather w1 JOIN weather w2ON w1.temp_lo < w2.temp_lo AND w1.temp_hi > w2.temp_hi;------------------------------- Aggregate Functions-----------------------------SELECT max(temp_lo)FROM weather;SELECT city FROM weatherWHERE temp_lo = (SELECT max(temp_lo) FROM weather);-- Aggregate with GROUP BYSELECT city, max(temp_lo)FROM weatherGROUP BY city;-- ... and HAVINGSELECT city, max(temp_lo)FROM weatherGROUP BY cityHAVING max(temp_lo) < 40;------------------------------- Updates:-- An UPDATE statement is used for updating data.------------------------------- Suppose you discover the temperature readings are all off by 2 degrees as-- of Nov 28, you may update the data as follow:UPDATE weatherSET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2WHERE date > '1994-11-28';SELECT * FROM weather;------------------------------- Deletions:-- A DELETE statement is used for deleting rows from a table.------------------------------- Suppose you are no longer interested in the weather of Hayward, then you can-- do the following to delete those rows from the table.DELETE FROM weather WHERE city = 'Hayward';SELECT * FROM weather;-- You can also delete all the rows in a table by doing the following. (This-- is different from DROP TABLE which removes the table in addition to the-- removing the rows.)DELETE FROM weather;SELECT * FROM weather;------------------------------- Removing the tables:-- DROP TABLE is used to remove tables. After you have done this, you-- can no longer use those tables.-----------------------------DROP TABLE weather, cities;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。