最近做一个项目时,因为一个小问题卡了半天,在使用distinct关键字查询mysql时报错:
select zaolin_user_tree.id, distinct zaolin_user_tree.carbonLayerNum, zaolin_user_tree.youjiRate,zaolin_user_tree.iniYouJiStore, zaolin_user_tree.changeRate, zaolin_user_tree.guanliRate,zaolin_user_tree.refYouJiStore, zaolin_user_tree.liyongRate from zaolin_user_tree where zaolin_user_tree.userId='1'
多次实验才发现需要将distinc关键字列放到查询的第一列才不会报错,这是因为mysql默认的会将通过distinct
进行分组,然后进行查询。