×ðÁú¿­Ê±

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
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿