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

How can I convert this query into a thinkphp query?

WBOY
Release: 2016-08-04 09:21:00
Original
957 people have browsed it

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template