1.テーブル内のすべてのデータの削除と同時に、それは自動的にクリアさに成長します。
truncate table SW_Admin_Log
2. DOは直接値の自動成長をリセットし、データテーブルを削除しません
dbcc checkident('SW_Admin_Log',reseed,0)
サブクエリ
select (select Title from SW_ProductType a where p.TypeID=a.ID )
nextNum, p.* from SW_Product p
where Model='Product'
select (select count(0) from SW_ProductType)
nextNum, a.* from SW_ProductType a
where ParentID=10354
//查询有几个子集
select (select count(0) from SW_ProductType where ParentID=a.ID) nextNum, a.* from SW_ProductType a
where ParentID=0
LEFT JOINは:LEFT JOINを
select b.Title TypeTitle,a.* from SW_Product a left join SW_ProductType b on a.TypeID=b.id
where a.Model='Product'
右の接続:RIGHT JOINを
select b.Title TypeTitle,a.* from SW_Product a right join SW_ProductType b on a.TypeID=b.id
where a.Model='Product'
連合
select b.Title TypeTitle,a.id from SW_Product a left join SW_ProductType b on a.TypeID=b.id
where a.Model='Product'
UNION
select b.Title TypeTitle,a.id from SW_Product a right join SW_ProductType b on a.TypeID=b.id
where a.Model='Product'
マルチテーブル共同調査
select c.ThumbUrl,b.Title,a.ProductName from SW_Product a,SW_ProductType b,SW_PicList c
where (a.TypeID=b.id and c.ProductID=a.id) and a.Model='product'
クエリをグループ化することにより、グループ
//sql server 语法
select convert(varchar,datepart(yy,AddDate))+'-'+convert(varchar,datepart(mm,AddDate)) a,count(0) num
from sw_product
group by convert(varchar,datepart(yy,AddDate))+'-'+convert(varchar,datepart(mm,AddDate))
//mysql 语法
select DATE_FORMAT(time,'%Y-%m') times from
user_login_log GROUP BY times
//mysql 复杂、连表、多条件分组查询
SELECT oi.business_id,b.`business_name`,b.`parent_id`,b.`business_icon`,COUNT(1) num
FROM order_info oi,business b
WHERE user_id=80
AND b.`business_id`=oi.`business_id`
and (select is_shelf from business where business_id=b.parent_id)=1
and b.is_shelf=1
GROUP BY oi.business_id,b.business_name,b.`parent_id`,b.`business_icon`
ORDER BY num DESC
LIMIT 30
SQL構文(フィルタ機能の重合条件)を有します
//mysql
select DATE_FORMAT(time,'%Y-%m') times,count(0) cc
from user_login_log
GROUP BY times
having cc>60
//sql server
select convert(varchar,datepart(yy,AddDate))+'-'+convert(varchar,datepart(mm,AddDate)) a,
count(0) num
from sw_product
group by convert(varchar,datepart(yy,AddDate))+'-'+convert(varchar,datepart(mm,AddDate))
having count(0)>30
基本的なCRUD
insert into user_login_log (time,id,...) values(1,2,...),(1,2,.....)
update user_login_log set time='1',id=2
select * from user_login_log
delete from user_login_log
mybaits foreachの使い方
<delete id="delLike">
delete from user_business_like where user_id=#{userId}
</delete>
<insert id="addLike">
insert into user_business_like
(user_id,business_id)
values
<foreach collection="list" item="item" separator="," >
(#{userId},#{item})
</foreach>
</insert>
//类似mysql:insert into user_business_like values (user_id,business_id) values (80,90),(80,90),(80,90)
MySQLの制限ページネーション
select * from business limit 0,10
//page p 第几页
//size s 取多少条
//(p-1)*s,s 0,10 取第一页,每页10条
//(p-1)*s,s 10,10 取第二页,每页10条
MYSQL取引二つの主な方法があります。
1、BEGINと、ROLLBACKは、達成するためにCOMMIT
- BEGIN トランザクションを開始
- ROLLBACKの トランザクションのロールバック
- COMMIT トランザクションの確認を
2、直接使用のSETは、MySQLの自動コミットモードを変更するには:
- = 0のSET AUTOCOMMIT を無効に自動送信します
- SET AUTOCOMMIT = 1は 、自動コミット有効