thinkphp怎麼查詢一張表中某個欄位資料重複次數最

時間 2021-10-14 22:23:54

1樓:

$model=m('answer');

$model->field('count(username) num,username')->group('username')->order('num desc')->limit('3');

//也可以使用普通的sql語句,然後$model->query()

2樓:

select `username`,count(`username`) as c from `answer` group by `username` order by c desc limit 10

這樣可以查詢出 那些username 和出現的次數這種複雜的表查詢可以用

$model = new model() // 例項化一個model物件 沒有對應任何資料表

$model->query("這裡是上面的sql語句");

3樓:小葉

select * from `answer` group by usernameorder by usernamedesc limit 2

4樓:tn瓶邪

select top 3

degree ,

count(1) as 人數

from

student

group by

degree

order by

degree desc

thinkphp如何獲取一個表2個欄位中相同的資料 20

5樓:匿名使用者

select `username`,count(`username`) as c from `answer` group by `username` order by c desc limit 10

這樣可以查詢出 那些username 和出現的次數;

$model = new model() // 例項化一個model物件 沒有對應任何資料表

$model->query("這裡是上面的sql語句");

6樓:不想說就別說了

這個用or查詢就可以了

(tel = '158***x') or (brel = '158***x')

//這裡是tp的寫法

//不知道對不對

//你可以測試一下

//我一般都是用m() -> query(sql語句)這樣去寫的

$model = m('表名');

$where['tel'] = array('eq','1589456125');

$where['btel'] = array('eq','1589456125');

$where['_logic'] = 'or';

$model -> where($where) -> oreder('id desc') ->  select();

sql怎麼將一張表的欄位賦值給另一張表

插入資料insert into tbytz userid select userid from tbuser更新資料則在tbuser和tbytz兩個表要有一個關係。如tbuser.a1 tbytz.a2update tbytz set tbytz.userid select userid from ...

SQL根據現有表一張表,想一張表,的這張表結構要

看你用的什麼資料庫 sql server select into table new from table old 複製結構和資料 select into table new from table old where 1 2 只複製結構 oracle create table table new a...

資料庫從一張表向另一張表怎麼插入資料

千鋒教育 下面以mysql資料庫為例分情況一一說明 兩張表 inserttest和inserttest2,前者中有測試資料 1.如果2張表的欄位一致,並且希望插入全部資料,可以用這種方法 insert into 目標表 select from 表 insert into inserttest sel...