如何查詢產品數量大於3條的店鋪信息

今天作小程序的時候碰到這樣一個問題,sql

界面上要求展現店鋪的三件產品,小程序

那麼產品數不足3件的,爲了防止頁面空白,3d

天然是不該該被查詢出來的。blog

想了半個小時仍是沒有結果,隨手往兄弟羣裏面一丟,開發

連我在內一共四個開發,除了一個沒冒泡的,產品

另外兩個都給了我一個答案,,it

我真是太渣了。。。class

廢話不說了,看sqlselect

$sql = "select id,shopname,totalsales,logo from pt_shop where id in(select shopid from pt_product group by shopid having count(*)>=3 ) order by id desc limit ".(($page-1)*5).",5";

 第二種更好一點程序

 $sql = "select s.id,shopname,totalsales,s.logo,count(p.id) as nums from pt_shop s left join pt_product p on s.id = p.shopid group  by p.shopid having  nums >=3 order by s.id desc limit ".(($page-1)*5).",5";
相關文章
相關標籤/搜索