//1.新增操作:insert into:插入 values:多個參數值 s:複數
insert into product (pid,pname,price,category_id)values(11,‘錘子’,1000.0,‘c001’)
//2.刪除當前指定id參數 影響的數據爲:1/0 ; 當前執行操作爲1的時候執行成功,爲零的時候執行失敗
delete from product where pid=11
//3.刪除全表操作 影響的數據欄:5;當前的數據5代表刪除5條數據
delete from product
//4.修改操作 set:設置 where:條件 pid:主鍵
update product set pname=“IBC” where pid=1;
//5.查詢全表操作
select * from product
//6.根據id查詢當前數據
select * from product where pid=1;
//7.查詢表中的某一列或者幾列
select pname,price from product
//8.別名操作,通過as進行別名添加
select pid as id,pname from product
//9.給當前表取別名,並通過當前別名進行調用當前表內部字段
select pid,a.pname from product a;
//10.列表達式
select pid,pname,price,category_id from product
//11.查詢當前價格爲800的數據
select * from product where price=800; <>:不等於
//12查詢價格不等於800數據 !=:不等於
select * from product where price!=800;
select * from product where price<>800;
//13查詢價格小於800數據
select * from product where price<800;
//14查詢價格大於800數據
select * from product where price>800;
//15查詢價格大於等於800數據
select * from product where price>=800;
//16查詢價格小於等於800的數據
select * from product where price<=800;
//17查詢價格不等於800數據
select * from product where not(price=800)
//18.查詢當前價格區間的參數 and:顯示在某一區間的值(含頭含尾)
select * from product where price>=800 and price<=2000
//19查詢當前價格區間的參數 BETWEEN and:顯示在某一區間的值(含頭含尾)
select * from product where price BETWEEN 800 AND 2000;
//20.查詢當前表多個條件任一成立
select * from product where price>=800 or price<=2000
//21.根據集合進行查詢操作in(100,2000)
select * from product where price in(800,2000)
//22.判斷當前表中字段爲null的數據查詢 is null:判斷爲空
select * from product where category_id is null
//23.查詢當前表中字段不爲空的數據 is not null:不爲空
select * from product where category_id is not null
//24.查詢姓o名稱 like:代表模糊查詢
select * from product where pname like’o%’
//25.查詢當前姓名中含有o名字
select * from product where pname like’%o%’
//26.查詢第二個名字爲o名稱
select * from product where pname like’_o%’
//27查詢當前名字中帶o的數據,且根據價格爲800來查詢
select * from product where pname like’%o%'and price=2000
//28.升序查詢操作 asc:升序
select * from product order by price asc
//29.降序操作 desc:降序
select * from product order by price desc
//30.在價格排序(降序)的基礎上,以分類排序(降序)
select * from product order by price desc,category_id desc;
//31.去重的同時並將當前的價格進行降序查詢
select DISTINCT price from product order By price desc
//32.結合列篩選和行篩選
select pname,price from product where pname like’%o%’ order by price desc
//33.統計指定列不爲NULL的記錄行數;
select count(*) from product
//34.統計指定列不爲NULL且數據值price價格大於800的行數
select count(*) from product where price>800
//35.統計當前數據中不重複的行數有多少條 distinct:去重操作
select count(distinct price) from product
//36.統計價格總和sum
select sum(price) from product
//37.查看當前max最大值
select max(price) from product
//38.查看當前min最小值
select min(price) from product
//39.查看當前數據平均值avg
select avg(price) from product
//40.分組 最好和聚合函數結合使用
select price from product group by price
//41.按照類別id分組 該類名的商品個數 平均價格 類別
select price,count(*),category_id from product group by category_id
//42.先行篩選再分組:對非空的category_id進行分組 注意where的位置
select avg(price),count(*),category_id from product where category_id is not null group by category_id
//43.篩選出評價價格在500以上的商品分組
select count(*),avg(price),category_id from product group by category_id having avg(price)>=500;
//44.實現登錄方法
select count(*) from user where username =? and password=? and state=1
//45.ajax校驗數據sql
select count(*) from user where username=?
//46.驗證郵箱
update user set state=1 where code=?
//47.註冊的插入數據庫
insert into user values(?,?,?,?,?,?,?,?,?,?)
//48.發現熱門商品並限制數量如0-9
select * from product where is_hot=? limit ?,?
//49.發現最新商品並限制數量(降序)
select * from product order by pdate desc limit ?,?
//50.查詢總條數
select count(*) from product where cid=?
//51.設置當前分頁數據參數
select * from product where cid=? limit ?,?
//52.返回商品所有的信息
select * from product where pid=?