sql语句
1、replace into用replace into 替代insert into 根据唯一主键判断 ,无则插入,有则删除重新插入(覆盖);不适用自增ID做主键。因为会删除id.
2.同表三级分销查询下级每代的人数(内联查询)
获取第二代的人;
SELECT a.user_name,a.reg_time,a.user_id FROM " . $ecs->table('users') . "a inner join" . $ecs->table('users') .
"b on a.parent_id = b.user_id" . " WHERE b.parent_id={$user_id}
获取第三代的人;
SELECT a.user_name,a.reg_time,a.user_id FROM " . $ecs->table('users') . " a inner join" . $ecs->table('users') .
" b on a.parent_id = b.user_id" . " inner join" . $ecs->table('users') . " c on b.parent_id = c.user_id " . " WHERE c.parent_id={$user_id}
3.不同的表联表查询
$sql = 'SELECT ad.ad_id, ad.ad_name, ad.ad_link, ad.ad_code '.
'FROM ' . $ecs->table('ad') . ' AS ad ' .
'LEFT JOIN ' . $ecs->table('ad_position') . ' AS p ON ad.position_id = p.position_id '.
"WHERE ad.ad_id = '$ad_id'
4.获取最近的sql语句
$modl = M();
$sql = $modl->getLastSql();