日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php join a.id b.id,mysql,sql_MySQL A left join B on B.cid=A.id 左链接查询失败,求解,mysql,sql - phpStudy...

發布時間:2024/9/30 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php join a.id b.id,mysql,sql_MySQL A left join B on B.cid=A.id 左链接查询失败,求解,mysql,sql - phpStudy... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL A left join B on B.cid=A.id 左鏈接查詢失敗,求解

mysql> desc fb_category;

+-------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+----------------+

| id | int(10) | NO | PRI | NULL | auto_increment |

| upid | int(10) | NO | MUL | NULL | |

| name | varchar(20) | NO | | NULL | |

| sort | int(4) | NO | | NULL | |

+-------+-------------+------+-----+---------+----------------+

4 rows in set (0.01 sec)

mysql> desc fb_relation;

+---------+---------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+---------+---------+------+-----+---------+----------------+

| id | int(10) | NO | PRI | NULL | auto_increment |

| siteid | int(10) | NO | MUL | NULL | |

| cid | int(10) | NO | MUL | NULL | |

| uptime | int(10) | NO | | NULL | |

| hit | int(10) | NO | | NULL | |

| hittime | int(10) | NO | | NULL | |

+---------+---------+------+-----+---------+----------------+

6 rows in set (0.01 sec)

對應關系

fb_category.id = fb_relation.cid

fb_site.id = fb_relation.siteid

實現需求

DROP VIEW IF EXISTS fb_v_category;

CREATE VIEW `fb_v_category` AS

select c1.*,

count(c2.`id`) AS `subtotal`,

count(r.id) as sitetotal

from `fb_category` c1

left join `fb_relation` r on r.cid=c1.id

left join `fb_category` c2 on c1.id=c2.upid

where c1.id=r.cid

group by c1.`id`

order by c1.`sort` asc, c2.sort asc ,sitetotal desc;

測試語句:創建成功

drop view if exists fb_v_category;

create view fb_v_category as

select c1.*,count(r.cid) as sitetotal

from fb_category c1

left join fb_relation r on c1.id=r.cid

group by c1.id

order by c1.sort asc

測試語句:創建成功

--視圖表創建正常

create view fb_v_category as

select c1.*,count(c2.upid) as subtotal

from fb_category c1

left join fb_category c2 on c2.upid=c1.id

group by c1.id

order by c1.sort asc

相關閱讀:

歷史記錄解決方案

composer ^ 這個符號什么意思不太明白?

如何用shell查詢每個用戶定時任務?

java多線程與python多線程同時進行io密集型操作

BIND里query.log記錄的到底是什么IP?

iOS里的sleep函數會阻塞什么

js字符串中如何判斷出現最多的字符是哪一個?

sql異常中的ibfk_1是什么意思?

線下機器ssh服務器, stty -a 后,查看到的結果是 0 或是 undef ,有誰知道是什么情況,我本地怎么設置嗎

yii2 中使用elasticsearch 進行模糊匹配

C++ vector容器如何快速讀取txt文檔數據?

PHP interface 代價非常高昂 請使用抽象類代替接口

node.js 的jade 模板引擎出錯

grunt-rev 找不到task任務?

有什么好辦法來確定,程序阻塞在哪里 ?

仿微信運動下拉出現占領封面人的圖片

聲波通信 檢測頻率時這幾句代碼是什么意思?

安裝libxml2的時候,error: use of undeclared identifier 'LZMA_OK'怎么解?

Node.js 使用 mongodb-native 連接 Mongodb 頻繁斷開連接,求解決方法?

冒泡事件和捕獲事件到底有什么區別?

總結

以上是生活随笔為你收集整理的php join a.id b.id,mysql,sql_MySQL A left join B on B.cid=A.id 左链接查询失败,求解,mysql,sql - phpStudy...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。