中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)站設(shè)計(jì) 聯(lián)系怎樣進(jìn)行網(wǎng)絡(luò)推廣效果更好

網(wǎng)站設(shè)計(jì) 聯(lián)系,怎樣進(jìn)行網(wǎng)絡(luò)推廣效果更好,建材網(wǎng)站建設(shè) 南寧,怎么做網(wǎng)站專題目錄 問題:SQL解答: 問題: 現(xiàn)在有一張relation表,里面只有兩個(gè)字段:from_user和to_user,代表關(guān)注關(guān)系從from指向to,即from_user關(guān)注了to_user?,F(xiàn)在要找出互相關(guān)注的所有人。 from_user to_…

目錄

  • 問題:
  • SQL解答:

問題:

現(xiàn)在有一張relation表,里面只有兩個(gè)字段:from_user和to_user,代表關(guān)注關(guān)系從from指向to,即from_user關(guān)注了to_user?,F(xiàn)在要找出互相關(guān)注的所有人。


from_user    to_user
孫悟空          唐僧
唐僧            如來(lái)佛祖
唐僧            觀音菩薩
觀音菩薩         如來(lái)佛祖
唐僧            孫悟空
孫悟空          玉皇大帝
玉皇大帝        如來(lái)佛祖
如來(lái)佛祖         觀音菩薩
如來(lái)佛祖         玉皇大帝
如來(lái)佛祖         唐僧
孫悟空          豬八戒
豬八戒            嫦娥
豬八戒           孫悟空
豬八戒           唐僧
豬八戒          沙僧
沙僧            豬八戒
沙僧            玉皇大帝
沙僧            孫悟空
沙僧            唐僧

SQL解答:

解答思路一:使用自關(guān)聯(lián)即可,這種方式簡(jiǎn)單也最易理解。適合數(shù)據(jù)量不是很大的情況,因?yàn)闀?huì)導(dǎo)致數(shù)據(jù)膨脹。


with tmp as
(
select '孫悟空' as from_user ,     '唐僧'   as to_user
union all
select '唐僧' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '唐僧' as from_user ,     '觀音菩薩'   as to_user
union all
select '觀音菩薩' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '唐僧' as from_user ,     '孫悟空'   as to_user
union all
select '孫悟空' as from_user ,     '玉皇大帝'   as to_user
union all
select '玉皇大帝' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '觀音菩薩'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '玉皇大帝'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '唐僧'   as to_user
union all
select '孫悟空' as from_user ,     '豬八戒'   as to_user
union all
select '豬八戒' as from_user ,     '嫦娥'   as to_user
union all
select '豬八戒' as from_user ,     '孫悟空'   as to_user
union all
select '豬八戒' as from_user ,     '唐僧'   as to_user
union all
select '豬八戒' as from_user ,     '沙僧'   as to_user
union all
select '沙僧' as from_user ,     '豬八戒'   as to_user
union all
select '沙僧' as from_user ,     '玉皇大帝'   as to_user
union all
select '沙僧' as from_user ,     '孫悟空'   as to_user
union all
select '沙僧' as from_user ,     '唐僧'   as to_user
)
select
a.from_user,
a.to_user,
if(b.from_user is not null, 1, 0) as is_friend -- 1:互相關(guān)注 
from tmp a
left join tmp b
on a.from_user=b.to_user and a.to_user=b.from_user
;

解答思路二:找到互相關(guān)注的人的規(guī)律,當(dāng)他們是互相關(guān)注時(shí),那么將from_user和to_user其中一個(gè)順序調(diào)換位置后,from_user和to_user就一定會(huì)出現(xiàn)兩條數(shù)據(jù)(源表提前已經(jīng)去重),所有出現(xiàn)兩條數(shù)據(jù)的人就是有互相關(guān)注的。這種方式不會(huì)導(dǎo)致數(shù)據(jù)膨脹。

with tmp as
(select '孫悟空' as from_user ,     '唐僧'   as to_user
union all
select '唐僧' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '唐僧' as from_user ,     '觀音菩薩'   as to_user
union all
select '觀音菩薩' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '唐僧' as from_user ,     '孫悟空'   as to_user
union all
select '孫悟空' as from_user ,     '玉皇大帝'   as to_user
union all
select '玉皇大帝' as from_user ,     '如來(lái)佛祖'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '觀音菩薩'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '玉皇大帝'   as to_user
union all
select '如來(lái)佛祖' as from_user ,     '唐僧'   as to_user
union all
select '孫悟空' as from_user ,     '豬八戒'   as to_user
union all
select '豬八戒' as from_user ,     '嫦娥'   as to_user
union all
select '豬八戒' as from_user ,     '孫悟空'   as to_user
union all
select '豬八戒' as from_user ,     '唐僧'   as to_user
union all
select '豬八戒' as from_user ,     '沙僧'   as to_user
union all
select '沙僧' as from_user ,     '豬八戒'   as to_user
union all
select '沙僧' as from_user ,     '玉皇大帝'   as to_user
union all
select '沙僧' as from_user ,     '孫悟空'   as to_user
union all
select '沙僧' as from_user ,     '唐僧'   as to_user
)
select
from_user
,to_user
,count(1) over(partition by feature) as is_friend ---1:不是 2:是
from
(selectfrom_user,to_user--當(dāng)有互相關(guān)注時(shí),保證只將其中的一對(duì)用戶調(diào)換from_user和to_user并拼接,if(from_user>to_user,concat(from_user,to_user),concat(to_user,from_user)) as featurefrom tmp
)t1
;
http://www.risenshineclean.com/news/58841.html

相關(guān)文章:

  • 做網(wǎng)站需要網(wǎng)站負(fù)責(zé)人推動(dòng)防控措施持續(xù)優(yōu)化
  • 提卡的網(wǎng)站怎么做查網(wǎng)站權(quán)重
  • 123邢臺(tái)招聘信息網(wǎng)鄭州企業(yè)網(wǎng)站seo
  • 微信開發(fā)網(wǎng)站建設(shè)天津網(wǎng)站優(yōu)化
  • 網(wǎng)站建設(shè)調(diào)查問卷天津網(wǎng)絡(luò)廣告公司
  • 如何做php分頁(yè)網(wǎng)站seo查詢愛站
  • 織夢(mèng)做的網(wǎng)站后臺(tái)頁(yè)優(yōu)化軟件
  • 專做壞消息的網(wǎng)站南寧seo產(chǎn)品優(yōu)化服務(wù)
  • 網(wǎng)站建設(shè)學(xué)院廣州網(wǎng)站建設(shè)公司
  • 網(wǎng)站建設(shè)哪個(gè)公司的好進(jìn)入百度知道首頁(yè)
  • 怎么用 c文件做網(wǎng)站頁(yè)面關(guān)鍵詞優(yōu)化
  • 企業(yè)網(wǎng)站建設(shè)方案書范文浙江新手網(wǎng)絡(luò)推廣
  • 做頭像網(wǎng)站長(zhǎng)沙網(wǎng)紅打卡景點(diǎn)排行榜
  • 無(wú)錫制作網(wǎng)站公司賣友情鏈接的哪來(lái)那么多網(wǎng)站
  • wordpress做的網(wǎng)站嗎整站seo外包
  • 外貿(mào)專業(yè)網(wǎng)站的公司江西網(wǎng)絡(luò)推廣seo
  • 廣州知名網(wǎng)站建設(shè)后臺(tái)管理便捷淘寶店鋪如何推廣
  • 中山 網(wǎng)站制作重慶seo優(yōu)化
  • 邯鄲網(wǎng)站建設(shè)公司哪家好建站軟件可以不通過網(wǎng)絡(luò)建設(shè)嗎
  • 怎么樣分析一個(gè)網(wǎng)站百度搜索引擎seo
  • b2b電子商務(wù)網(wǎng)站開發(fā)在線排名優(yōu)化工具
  • 公司官網(wǎng)定制上海網(wǎng)站排名seo公司哪家好
  • ui設(shè)計(jì)是什么職位aso優(yōu)化是什么
  • 怎么修改網(wǎng)站源文件十大基本營(yíng)銷方式
  • 零食網(wǎng)站制作的建設(shè)大綱域名查詢138ip
  • 四大網(wǎng)站手機(jī)百度引擎搜索入口
  • 東營(yíng)市做網(wǎng)站優(yōu)化中國(guó)seo誰(shuí)最厲害
  • 石家莊企業(yè)網(wǎng)絡(luò)推廣廣東網(wǎng)站se0優(yōu)化公司
  • 網(wǎng)站開發(fā)需要哪些技術(shù)搜索引擎排名優(yōu)化是什么意思
  • 重慶網(wǎng)網(wǎng)站建設(shè)公司長(zhǎng)春網(wǎng)站建設(shè)技術(shù)支持