×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphp5ÔõÑùÈ¥³ýÖظ´ÅÌÎÊ

Ò»¡¢Ê¹Óà SELECT DISTINCT Òªº¦×Ö

ÔÚ SQL Óï¾äÖУ¬¿ÉÒÔʹÓà SELECT DISTINCT Òªº¦×ÖÀ´»ñÈ¡²»Öظ´µÄÊý¾Ý¡£ÔÚ ThinkPHP5 ÖУ¬Ê¹Óà \think\Db ÀàµÄ query() ÒªÁìÖ´ÐÐ SQL ÅÌÎÊÓï¾äʱ£¬¿ÉÒÔÖ±½ÓÔÚÅÌÎÊÌõ¼þÖÐʹÓà SELECT DISTINCT Òªº¦×Ö£¬ÀýÈ磺

use \think\Db;

$data = Db::query('SELECT DISTINCT `brand` FROM `goods` WHERE `category_id` = 1');

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇͨ¹ý SELECT DISTINCT Òªº¦×Ö»ñÈ¡ÁË goods ±íÖÐ category_id Ϊ 1 µÄËùÓÐÆ·ÅÆ£¬²¢½«ÅÌÎÊЧ¹û¸³Öµ¸øÁË $data ±äÁ¿¡£

¶þ¡¢Ê¹Óà distinct() ÒªÁì

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

³ýÁËÔÚ SELECT Óï¾äÖÐʹÓà SELECT DISTINCT Òªº¦×ÖÍ⣬»¹¿ÉÒÔʹÓà ThinkPHP5 ÌṩµÄ distinct() ÒªÁìʵÏÖÈ¥ÖØÅÌÎÊ¡£ÈçÏÂËùʾ£º

use \think\Db;

$data = Db::name('goods')
    ->where('category_id', 1)
    ->distinct(true)
    ->field('brand')
    ->select();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁË Db ÀàµÄ name() ÒªÁìÖ¸¶¨ÁËÅÌÎʵÄÊý¾Ý±í£¬Ê¹ÓÃÁË where() ÒªÁìÖ¸¶¨ÁËɸѡÌõ¼þ£¬Ê¹ÓÃÁË distinct() ÒªÁ쿪ÆôÁËÈ¥ÖØÅÌÎÊ£¬Ê¹ÓÃÁË field() ÒªÁìÖ¸¶¨ÅÌÎʵÄ×ֶΣ¬×îºóʹÓÃÁË select() ÒªÁìÖ´ÐÐÅÌÎʲÙ×÷¡£

Èý¡¢Ê¹Óà group() ÒªÁì

³ýÁËʹÓà SELECT DISTINCT Òªº¦×ÖºÍ distinct() ÒªÁìÍ⣬»¹¿ÉÒÔʹÓà group() ÒªÁìʵÏÖÈ¥ÖØÅÌÎÊ¡£ÈçÏÂËùʾ£º

use \think\Db;

$data = Db::name('goods')
    ->where('category_id', 1)
    ->group('brand')
    ->select();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁË Db ÀàµÄ name() ÒªÁìÖ¸¶¨ÁËÅÌÎʵÄÊý¾Ý±í£¬Ê¹ÓÃÁË where() ÒªÁìÖ¸¶¨ÁËɸѡÌõ¼þ£¬Ê¹ÓÃÁË group() ÒªÁì¾ÙÐзÖ×飬×îºóʹÓÃÁË select() ÒªÁìÖ´ÐÐÅÌÎʲÙ×÷¡£

ÔÚÏÖʵµÄ¿ª·¢ÊÂÇéÖУ¬ÎÒÃÇÐèҪƾ֤ÏêϸµÄÓªÒµÐèÇóÑ¡ÔñºÏÊʵÄÈ¥ÖØÅÌÎÊÒªÁ죬ÒÔ°ü¹ÜÅÌÎÊЧ¹ûµÄ׼ȷÐÔºÍЧÂÊ¡£

ÒÔÉϾÍÊÇthinkphp5ÔõÑùÈ¥³ýÖظ´ÅÌÎʵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ