依旧还是新人请教,请指点,如下:
现有一张表中包含以下两个字段:1)ID 标识用户;2)Goods_Type标识用户购买物品种类;表中的条目记录用户一天的购买行为。一个用户可能在一天里面有多条条目对应其购买行为。
现在要完成以下操作:
查询表中购买了Goods_Type=5的用户的数量,如果一个用户有两条购买了Goods_Type=5的行为,也算作一个数量,现在有两种实现方式:
1)select count(distinct(ID)) from tb where Goods_Type=5;
2) create table temptb select count(if((Goods_Type=5),true,null)) as GT5_Num from tb group by ID;
   create count(if((GT5_Num>0),true,null)) from temptb;高手指点一下,哪种方法执行的效率高,多谢多谢!