sql语句应用

laravel5.6框架中用到的sql语句

        //排序
$data=DB::table('admin')->select(array('id','name','password'))->orderBy('name')->get();
//去除重复数据
$data=DB::table('admin')->select('name')->distinct('name')->get();
//分组
$data=DB::table('admin')->select(array('id','name','password'))->get()->groupBy('name');
//获取限定条件以外的数据
$data = DB::table('admin')->offset()->limit()->get();
$data = DB::table('admin')->skip()->take()->get();
//限定
$data = DB::table('admin')->limit()->get();
$data = DB::table('admin')->take()->get();

sql源生语句

//去除重复数据
select distinct (name) from admin
//分组
select * from tablename group by name,age
//清空表记录
truncate table tablename 清空表记录,id重置
//分组统计数据
SELECT site_id,SUM(access_log.count) AS nums from access_log GROUP BY site_id;
//根据字段排序
select * from access_log ORDER BY date
//统计
SELECT SUM(count) as sum from access_log
//获取最大值
SELECT max(access_log.count) as sum from access_log
//获取最小值
SELECT min(access_log.count) as sum from access_log

  

上一篇:bootstrap modal


下一篇:01-HTML介绍