查询的自定义结果需要插入到新表,但是还得自己定义新表,懒得手工创建表,则使用语句快速建表,然后再去调整表结构
create TABLE app.dm_x2_vip_check_res as SELECT a.vip_id AS x2_vip_id, a.vip_mobile AS x2_vip_mobile, a.channel_brand AS x2_channel_brand, a.grade_id AS x2_grade, a.vip_birth_date AS x2_vip_birth_date, a.depot_id AS x2_depot_id, a.extend_user_id AS x2_extend_user_id, b.vip_id AS dm_vip_id, b.vip_mobie AS dm_vip_mobile, b.channel_brand AS dm_channel_brand, b.grade_code AS dm_grade_id, b.vip_birthday AS dm_vip_birth_date, b.depot_id AS dm_depot_id , b.clerk_code AS dm_extend_user_id FROM dim.dim_vip a INNER JOIN dim.dim_vip_dm b ON a.vip_id = b.vip_id AND ( a.vip_mobile != b.vip_mobie OR a.channel_brand != b.channel_brand OR a.grade_id != b.grade_code OR a.vip_birth_date != b.vip_birthday OR a.depot_id != b.depot_id OR a.extend_user_id != b.clerk_code ) WHERE a.create_date < DATE_SUB( NOW(), INTERVAL 2 DAY ) ORDER BY a.create_date ASC
下面的是商品数据表,id是主键,catename是分类,titile是标题,price是价格,现在要求计算每种分类下的商品平均价格.id catename &n...
where与having非常类似.都能筛选数据.表达式完全一致. 但是职责的确不同.where负责对表中的字段进行筛选,having负责对where筛选后的结果集再次筛选。这也就是where不能使用别名字段来筛选的原因,因为数据中没有这个字段。&n...
需求查询出存在商品的商品分类. 先看看分类表:id(分类的id) catename(分类名) 1 手机 2 &n...
已有表名log来记录用户日志,id是主键,uid是用户id,rmk是备注,addtime是时间戳,需要取出不重复的用户日志记录默认的结果集:id uid rmk ...
(1).下面是一张基本的会员表membermid name age 1 高峰 24 2 王小 19 3 韩星 24(2).下面是一张基本的会员日志表loglid ...
concat函数用于连接多个字段和字符串,假如有一张用户表,希望将姓名和国籍字段同时合并输出。原表内容:id name country 1 张三 中国 2 李四 日本 3 王五 美国SQL语句:SELECT CONCAT(name,' (',count...