sql Ini示例SQL Snipet代码选择,删除,更新,插入加入

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Ini示例SQL Snipet代码选择,删除,更新,插入加入相关的知识,希望对你有一定的参考价值。

--Select
SELECT home_id, home_type, bathrooms
FROM homes
WHERE home_id < 500
AND home_type = 'two-storey'
ORDER BY home_type ASC, bathrooms DESC;

--Sample2
SELECT *
FROM homes
WHERE bathrooms >= 2
ORDER BY home_type ASC;

--Another
SELECT * FROM contacts
WHERE last_name = 'Smith'
AND contact_id >= 1000
AND contact_id <= 2000;

--Between
SELECT *
FROM contacts
WHERE last_name = 'Smith'
AND contact_id BETWEEN 1000 AND 2000;


----------------------------------------------------------

--CREATE TABLE
CREATE TABLE suppliers
( supplier_id number(10) not null,
  supplier_name varchar2(50) not null,
  city varchar2(50),
  CONSTRAINT suppliers_pk PRIMARY KEY (supplier_id)
);

INSERT INTO suppliers (supplier_id, supplier_name, city)
VALUES (5001, 'Microsoft', 'Chicago');

INSERT INTO suppliers (supplier_id, supplier_name, city)
VALUES (5002, 'IBM', 'Chicago');

INSERT INTO suppliers (supplier_id, supplier_name, city)
VALUES (5003, 'Red Hat', 'Detroit');

INSERT INTO suppliers (supplier_id, supplier_name, city)
VALUES (5004, 'NVIDIA', 'New York');

----------------------------------------------------------

--Delete
DELETE FROM customers;

DELETE FROM customers
WHERE last_name = 'Smith';


----------------------------------------------------------
--Update Data

--Multiple single column
UPDATE customers
SET last_name = 'Anderson'
WHERE customer_id = 5000;

--Multiple column
UPDATE customers
SET state = 'California',
    customer_rep = 32
WHERE customer_id > 100;

--Update Data from another table
UPDATE customers
SET c_details = (SELECT contract_date
                 FROM suppliers
                 WHERE suppliers.supplier_name = customers.customer_name)
WHERE customer_id < 1000;

----------------------------------------------------------

--Insert
INSERT ALL
  INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
  INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
  INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
SELECT * FROM dual;


INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(5000, 'Apple');


INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE customer_id > 5000;


INSERT INTO clients
(client_id, client_name, client_type)
SELECT supplier_id, supplier_name, 'advertising'
FROM suppliers
WHERE NOT EXISTS (SELECT *
                  FROM clients
                  WHERE clients.client_id = suppliers.supplier_id);
                  
----------------------------------------------------------
--Join Table


--SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_date
--FROM suppliers 
INNER JOIN orders
LEFT OUTER JOIN orders
RIGHT OUTER JOIN orders
FULL OUTER JOIN orders
--ON suppliers.supplier_id = orders.supplier_id;

以上是关于sql Ini示例SQL Snipet代码选择,删除,更新,插入加入的主要内容,如果未能解决你的问题,请参考以下文章

Oracle SQL示例

json Vue组件snipet。 VS代码

代码审计PHP项目注入&搜索&调试&SQL监控

sh TCP test_retry连接bash代码snipet

sql [sql]选择表达式示例时的大小写

如何优化 sql 查询以避免在没有 php.ini 或设置时间限制的情况下执行最长时间 [关闭]