查询的自定义结果需要插入到新表,但是还得自己定义新表,懒得手工创建表,则使用语句快速建表,然后再去调整表结构
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...
我们从一个结果集中查询信息一般都是select * from (select...),每次都要编写from (select...)非常麻烦,于是我们将结果集保存起来,这就是视图的便利。创建视图的命令为:create view &nb...
1.查看所有表,包括视图表,show tables;2.查看表结果,包括视图表,desc 表名3.查看建表过程,show create table 表名;4.查看建视图过程,show create view...
1.floor(x)返回小于x的整数,向下取整,用法,商品的价格是浮点型的,需要向下取整 eg:select id,title,floor(price) from shopgoods2.rand()返回0-1之间的随机数 select rand() select rand()...