Sql常用語法總結(mySql)超詳細版
create datebase ipay; 建立資料庫
drop datebase ipay; 刪除資料庫
create table t_urm_pinf(
usr_no varchar2(12) default 0 not null ,
usr_id number(12) default 0 not null
)
comment on table T_URM_PINF is '手機使用者資訊表'; 表名說明
comment on column T_URM_PINF.usr_no :欄位說明
create table t_urm_acin like t_urm_pinf :欄位加索引複製 。
create table t_urm_acin as select usr_no... from t_urm_pinf definition only ;僅僅複製欄位 。
刪除表 drop table t_urm_pinf ;
增加一列 alter table t_urm_pinf add xxx varchar2(12) default 0 not null;
e : alter table ipay.t_urm_pinf add payseq_flg varchar2(1) default 'N' not null;
新增主鍵 alter table t_urm_pinf add primary key(usr_no);
刪除主鍵 alter table t_urm_pinf drop primary key(usr_no)
建立索引
e: Create Index i_deptno_job on emp(deptno,job); —>在emp表的deptno、job列建立索引。
刪除索引 :drop index i_deptno_job
建立檢視 create view my_view as select usr_no from t_urm_pinf;
刪除檢視 drop view my_view
sql常用函式關鍵字
desc:降序,asc:升序
總數:select count from t_urm_pinf
求和:select sum()from t_urm_pinf
平均:select avg(usr_no) from t_urm_pinf
最大:select max(usr_no) from t_urm_pinf
最小:select min(usr_no) from t_urm_pinf
複製表 select top 0 * into b from a
拷貝表 insert into b(a, b, c) select d,e,f from b;
外連線查詢(表名1:a 表名2:b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
線上檢視查詢:select usr_no from (select a,b,c from t_urm_pinf) t where t.a='1';
between語法:
select * from t_urm_pinf a where a.id between a and b ;
select * from t_urm_pinf a where a.id not between a and b;
in語法
select *from t_urm_pinf a where a.id [not] in('a','b','c');
刪除主表中在副表中已經沒有的資料
delect from a where not exists(select *from b where a.a = b.a);
四表聯查問題:
select * from a left inner join b on a.a = b.a right inner join c on a.c = c.c inner join d on a.d = d.d where ...;
返回兩個日期之間的天數。select DATEDIFF(c_dt,e_dt)as dt c_dt和e_dt是合法日期格式。
mysql前十條記錄 select top 10 * from t_urm_pinf;
oracle 的隨機取出十條記錄:
select * from table_name where rownum<X --X為前多少條記錄
select * from (select a.*,a.rownum rn from (select * from table_name) a where a.rownum<M) where rn>n --這句就是從n到m也的資料,分為三層結構
選擇在每一組b值相同的資料中對應的a最大的記錄的所有資訊(類似這樣的用法可以用於論壇每月排行榜,每月熱銷產品分析,按科目成績排名,等等
select * from t_urm_pinf up where up.a = (select max(a) from t_acm_acin aa where aa.b= up.b)
隨機取一條資料
select * from (select * from t_urm_pinf order by dbms_random.value) where rownum = 1;
刪除重複記錄
(中間表方法)select distinic * into a from b ;
delect from b;
insert into b select * from a;
delect from t_urm_pinf where usr_no not in (select max(usr_no) from t_urm_pinf group by list1,list2,list3...所有列 );
所有列查詢不重複的列,然後刪除除不重複列以外的其他列。
包括所有在 TableA 中但不在 TableB和TableC 中的行並消除所有重複行而派生出一個結果表
(select * from a)expect(select * from b)expect(select * from c)
日期格式
SELECT hiredate
FROM employees
WHERE hiredate between cast('1993-10-17' as datetime) and cast('1994-01-02' as datetime)
相關推薦
Sql常用語法總結(mySql)超詳細版
create datebase ipay; 建立資料庫 drop datebase ipay; 刪除資料庫 create table t_urm_pinf( usr_no varchar2(12) default 0 not null , usr_id number(
MySql資料庫常用命令總結(全)
一、資料庫級命令 1. 資料庫連線 命令:mysql -h主機地址 -u使用者名稱 -p使用者密碼 –port=3307 1、找到安裝目錄bin, 進入該工作目錄,鍵入該命令mysql -u root -p,提示輸入密碼,使用者名稱前可以有空格也可以沒
Mysql資料庫常用操作總結(一)
一、windows下mysql資料庫備份1.1 說明 mysql資料庫備份的方法有很多,接下來要說的是用navicat進行備份,過程超簡單。1.2 過程 1)資料庫的備份找到要備份的資料庫(xqdb),單擊右鍵,選擇“轉儲SQL檔案”,儲存到電腦桌面,如下:此時,桌面上會
js基本語法總結(一)
向上取整 取余 轉字符串 結果 lin ase 調試 錯誤 進行 1.js簡介 a)js是一種網頁腳本語言,使得瀏覽器可以與網頁互動。 js的一種基於對象和事件驅動,具有安全性能的腳本語言,腳本語言就是在客戶端的瀏覽器就可以互動響應處理程序的語言,而不需要服務器的處理和響應
sql練習60題(mysql)
lac red distinct style creat select primary 數據 ima 兩張表:員工表、部門表 準備數據 CREATE DATABASE oa; USE oa; CREATE TABLE dept( deptno INT PRIMARY
Scala基本語法總結(一)
Scala基本語法總結 時隔快一年了,又撿起scala,不是想學的有多麼的精通,只是想把之前遇到的知識點和實踐中遇到的重點進行歸納總結,對以後的面試或許有點幫助吧! 一、scala開發環境的配置 我這裡分享一下有道雲筆記的地址,有之前學習的時候對scala的安裝方法的詳細描述,有興趣的可以看看 http
Oracle資料庫常用操作總結(一)
--oracle cs架構軟體 --客戶端 --tns --協議 --ip --埠 --資料庫名字 --監聽如果出了問題,先刪除所有監聽,再重建。netca。tns檔案中名字不能重複, --oracle預設自帶兩個管理員使用者 sys system 這兩個使用者在登入時
SQL Server視訊總結(四)
引言:SQL Server視訊的第四章是針對表(tabel)的管理,所以這章的重要性不言而喻,話不多說,我們開始總結 第四章 資料表管理 一、.欄位的資料型別 -數字資料型別 1.整數資料型別 (bigint、-int、smallin
SQL Server視訊總結(五)
引言:相對第四章的比較細化、針對物件較單一的知識點,第五章的內容對於資料庫來說,則較為巨集觀:索引、檢視和架構。 第五章 操作架構、索引和檢視 一、建立檢視 方法1: CREATE VIEW view_name(view_column_name) AS
【 Linux 】常用命令總結(更新)
通過需求去總結一些命令是記憶的一個好方法,正在實踐中。 對檔案以及資料夾的操作命令: touch test.txt //建立一個
python基礎語法總結(五)-- 字典dic + 元組tuple
目錄 一. 字典 1. 讀取 2. 新增 3. 修改 4. 刪除 5. 清空 6. 複製文字 7 遍歷 a. 遍歷鍵值對 b. 遍歷鍵 c. 遍歷值 二. 元組 一. 字典 字典型別類似於鍵值對key-value的一種資料結構,其中鍵不能重
Linux常用命令總結(五):sudo許可權
一、實現功能 使普通使用者hadoop具有root使用者許可權。 二、sudo 許可權 1.管理員(root)身份執行 vi /etc/sudoers 2.配置/etc/sudoers ## Allow root to run any commands anywh
Git 常用命令總結(一)
一、設定基本資訊 git config --global user.name "xiaobu" git config --global user.email "[email protected]" 檢視配置資訊 git config --list 設定本地
SpringCloud常用配置總結(轉)
原作者未知,但很佩服這種收集的能力。 server server.address 指定server繫結的地址 server.compression.enabled 是否開啟壓縮,預設為false. server.compression.excluded-user-
python基礎語法總結(六)-- python類與OOP面向物件特性
python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表
python基礎語法總結(四)-- list列表
python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表
python基礎語法總結(二)-- 函式function
python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表
python基礎語法總結(三)-- 數與字串
python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表
python基礎語法總結(一)-- python型別轉換函式+檔案讀寫
python常用系統函式方法與模組 python基礎語法總結(一)-- python型別轉換函式+檔案讀寫 python基礎語法總結(二)-- 函式function python基礎語法總結(三)-- 數與字串 python基礎語法總結(四)-- list列表
思科模擬器常用命令總結(續)
序 這是針對前面一篇博文的更新補充,關於思科模擬器常用的一些命令。這部分主要是交換機的常用命令。 常用命令 交換機常用命令 交換機基本狀態: switch: