簡體   English   中英

如何使用cakephp find從MySQL表中找到共同的朋友及其計數

[英]How to find mutual friends and their count from a mysql table using cakephp find

我如何獲取具有相同鏈接的記錄,並顯示數據庫中重復的次數及其計數。 示例數據和表結構在下面提到。 我正在使用cakephp框架,查詢如下所示:

這些記錄在這里具有相同的鏈接,我只需要顯示此記錄一次,在這里將其計數為2。

$socialList =   $this->SocialImportGeneral->find('all',array(
                                'joins'=>$where,
                                'conditions'=>$conditions,
                                'fields'=>array(
                                    'SocialImportGeneral.social_import_general_id',
                                    'SocialImportGeneral.display_name',
                                    'SocialImportGeneral.designation',
                                    'SocialImportGeneral.company',
                                    'SocialImportGeneral.industry',
                                    'SocialImportGeneral.location',
                                    'SocialImportGeneral.image',
                                    'SocialImportGeneral.link',
                                    'SocialImportGeneral.processed',
                                    'SocialImportGeneral.remarks',
                                    'SocialImportGeneral.social_import_revision_id',
                                    'SocialImportRevision.fourthambit_id'
                                ),
                                'limit'=>15,
                                'offset'=>$offset,
'group'=>array('SocialImportGeneral.display_name')
                            ));

這是我的表結構:

CREATE TABLE IF NOT EXISTS `social_import_general` (
  `social_import_general_id` int(11) NOT NULL AUTO_INCREMENT,
  `id` double DEFAULT NULL,
  `display_name` varchar(450) DEFAULT NULL,
  `designation` varchar(750) DEFAULT NULL,
  `company` varchar(600) DEFAULT NULL,
  `industry` varchar(600) DEFAULT NULL,
  `location` varchar(600) DEFAULT NULL,
  `search` varchar(750) DEFAULT NULL,
  `image` varchar(600) DEFAULT NULL,
  `link` varchar(750) DEFAULT NULL,
  `social_import_revision_id` int(11) DEFAULT NULL,
  `processed` tinyint(2) NOT NULL DEFAULT '0' COMMENT '0 - default 1 - no action take 2 - onhold',
  `remarks` varchar(250) DEFAULT NULL,
  `import_type` tinyint(1) NOT NULL COMMENT '1 =  fileimport , 2 = friendslist ',
  `ref_user_id` int(11) DEFAULT NULL COMMENT 'The user from which this record is fetched from social_login_friends table',
  `social_directory_id` int(11) DEFAULT NULL,
  `created_date` datetime NOT NULL,
  `modified_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `delete_status` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`social_import_general_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

在這里,我有類似的記錄:

3253
NULL
Sunny
NULL
NULL
NULL
NULL
NULL
https://graph.facebook.com/759390230759125/picture...
https://www.facebook.com/profile.php?id=7593902307...
73
0
NULL
2
10443
2
2015-04-09 11:28:53
2015-04-09 11:32:43
1
0

========================

3253
NULL
Sunny
NULL
NULL
NULL
NULL
NULL
https://graph.facebook.com/759390230759125/picture...
https://www.facebook.com/profile.php?id=7593902307...
73
0
NULL
2
10444
2
2015-04-09 11:28:53
2015-04-09 11:32:43
1
0

我嘗試了分組方式,但沒有成功。 我需要獲取此表中具有相同鏈接的重復記錄的計數。 任何幫助表示贊賞。

$socialList =   $this->SocialImportGeneral->find('all',array(
                                'joins'=>$where,
                                'conditions'=>$conditions,
                                'fields'=>array(
                                    'count(*) as TotalCount',
                                    'SocialImportGeneral.social_import_general_id',
                                    'SocialImportGeneral.display_name',
                                    'SocialImportGeneral.designation',
                                    'SocialImportGeneral.company',
                                    'SocialImportGeneral.industry',
                                    'SocialImportGeneral.location',
                                    'SocialImportGeneral.image',
                                    'SocialImportGeneral.link',
                                    'SocialImportGeneral.social_directory_id',
                                    'SocialImportGeneral.email_id',
                                    'SocialImportGeneral.processed',
                                    'SocialImportGeneral.remarks',
                                    'SocialImportGeneral.social_import_revision_id',
                                    'SocialImportRevision.fourthambit_id'
                                ),
                                'limit'=>15,
                                'offset'=>$offset,
                                'group'=>array('SocialImportGeneral.link,SocialImportGeneral.email_id HAVING COUNT(*) >= 1'),
                                'order'=>'TotalCount DESC',
                            ));

按順序分組是我的把戲,謝謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM