Home  >  Article  >  Backend Development  >  How can I convert this query into a thinkphp query?

How can I convert this query into a thinkphp query?

WBOY
WBOYOriginal
2016-08-04 09:21:00907browse

select count(*) from (select uid from oc_commission group by uid) as uid

Reply content:

select count(*) from (select uid from oc_commission group by uid) as uid

Your sql can be optimized and it can be done in one sentence

select count(distinct(uid)) from oc_commission

tp:
M('Commission')->count(distinct(uid));

How can I convert this query into a thinkphp query?

You can directly query using native code

http://www.kancloud.cn/manual/thinkphp/1775 The manual has subqueries, please take a look at it
$sql=M('oc_commission')->field('uid')->group(' uid')->select(false);
$count=M('oc_commission')->table($sql.' a')->count()
If an error is reported, go to github to download the latest version. An error will be reported

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn