我想問一些關於WHERE子句計數的問題。我已經研究過它,但沒有找到任何解決方案。如何計算WHERE子句的字段
我有2個表:
表1包含:
id, level, instansi
表2包含:
id, level, table1ID
問:
如何顯示table1.instansi
僅當行數table2 less than 2
。
條件
table2.table1ID = table1.id
我想問一些關於WHERE子句計數的問題。我已經研究過它,但沒有找到任何解決方案。如何計算WHERE子句的字段
我有2個表:
表1包含:
id, level, instansi
表2包含:
id, level, table1ID
問:
如何顯示table1.instansi
僅當行數table2 less than 2
。
條件
table2.table1ID = table1.id
Select t1.instanci From table1 t1 inner join table2 t2 on t1.table1id=t2.table2id
Group by t2.table2id Having count(t2.table2id)<2
select t1.*
from table1 t1 join table2 t2 on t2.table1ID=t1.id
group by t1.id
having count(*)<2
感謝您的答覆:) – Rabindra
你需要使用having子句中使用計數where子句
select t1.instanci
from table1 t1 inner join table2 t2
on t1.table1id=t2.table2id
group by t2.table2id
having count(t2.table2id)<2
的一種方法可以是,使一個查詢來選擇所有的行,然後計數行
$查詢=( 「SELECT * from表」);
$ result = mysqli_query($ con,$ query);
$ count = mysqli_num_rows($ result);
使用$計數,如果條件
感謝您的迴應:) – Rabindra
有多快!謝謝,它解決了我的問題.. :) – Rabindra