2017/2/13
查詢:select * from c2_company;
唯一值:
select distinct company_type from c2_company;
更精確的查詢:
select * from c2_company c where c.`company_name`='劉歡的de';
and:
select * from c2_company c where c.`company_name`='劉歡的de' and c.`company_type`='t';
or:select * from c2_company c where c.`company_name`='劉歡的de' or c.`company_type`='r';
order by 公升序:
select * from c2_company order by parent_id;
desc 降序:
select * from c2_company order by parent_id desc;
update 修改:
update c2_company set company_name ='歡歡波波' where company_name ='劉歡的de';
delete 刪除:
delete from c2_company where company_name='bobo';
insert into 插入:
insert into c2_company(id,company_name) values (6,huanhuan);
like 模糊查詢:
select * from c2_company where company_name like '歡%';
select * from c2_company where company_name like '%商';
select * from c2_company where company_name like '%小玩意%';
select * from c2_company where company_name not like '%小玩意%';
top 摘取:
select top 5 * from c2_company;
select top 50 percent * from c2_comapny;
mysql中語法 limit :
select * from c2_company limit 5;
oracle中語法 :
select * from c2_company where rownum <='6';
in 在where子句子中規定多個值:
select * from c2_company where company_type in ('t','r');
between ^ and ^ 選取這個範圍內的值:
select * from c2_company where id between 2 and 40;
asalias 別名:列
select id as '排序',company_name as'公司名稱' from c2_company;
join 通過兩個或多個表相同的部分,把錶結合起來:
通過兩個表相同的部分進行結合:
select c2_company.`company_code`,c2_store.`back_number`from c2_company,c2_store
where c2_company.`area_id_fk`=c2_store.`area_id_fk`;
inner join ^ on 表中至少有乙個匹配:
select c2_company.`company_code`,c2_store.`counter_number` from c2_company inner join c2_store on c2_company.`area_id_fk`=c2_store.`area_id_fk`;
left join ^ on 從左表有符合條件的行,即使右表沒有符合條件的行。
select c2_company.`company_code`,c2_store.`counter_number` from c2_company left join c2_store on c2_company.`area_id_fk`=c2_store.`area_id_fk`;
right join ^ on 從右表有符合條件的行,即使左表沒有符合條件的行。
select c2_company.`company_code`,c2_store.`counter_number` from c2_company right join c2_store on c2_company.`area_id_fk`=c2_store.`area_id_fk`;
full join ^on 只要某個表存在匹配
select c2_company.`company_code`,c2_store.`counter_number` from c2_company full join c2_store on c2_company.`area_id_fk`=c2_store.`area_id_fk`;
union 合併兩個或多個 select 語句的結果集
union 合併不重複:
select e_name from employees_china
union
select e_name from employees_usa;
union all 合併所有,會重複:
select e_name from employees_china
union all
select e_name from employees_usa;
SQL語法學習
union 操作符用於合併兩個或多個 select 語句的結果集。請注意,union 內部的 select 語句必須擁有相同數量的列。列也必須擁有相似的資料型別。同時,每條 select 語句中的列的順序必須相同。sql union 語法 select column name s from tabl...
SQL語法學習
sql語法 注意 sql語法中,增刪改查是我們剛開始學的重中之重。1 新增新的資料 1 第一種形式不需要插入列名,只需要插入值 一般所有列需要新增值的時候使用這種形式 注意 被設定為自增列的那一列不需要手動新增 語法 insert into table values value1,value2,va...
SQL語法學習二
case when.else.and substring case when logic then expression1 else expression2 有點像if.else.substring columnname,start,len 擷取某column從開始start的位置到一定長度len ...