我要生成此SQL代码:
Select count(distinct user_id) as ui
from posts
我尝试了此代码段,但没有用:
knex('posts').countDistinct('user_id').as('ui');
我该怎么做?
答案 0 :(得分:2)
我发现count()和countDistinct都可以像这样解析原始查询:
knex('posts').countDistinct('user_id as ui') ;
knex('posts').count('user_id as ui') ;