久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有聯(lián)合和連接的 SQL 查詢

SQL Query with union and join(帶有聯(lián)合和連接的 SQL 查詢)
本文介紹了帶有聯(lián)合和連接的 SQL 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的設置是這樣的

表1:company_group - company_id, company_name表 2:商店 - store_id、store_name表 3:銷售額 - sales_id、company_id、store_id、日期、銷售額表 4:wh_sales - wh_sale_id、company_id、store_id、日期、銷售額表5:購買-purchase_id、company_id、store_id、日期、購買

現在我可以使用 select 和 union 查詢獲取前四個表的數據,但是我無法弄清楚應該如何以及使用哪個連接來獲取同一個表中 table5 的數據

我正在使用前四個表的查詢

選擇`company_group`.`company_name,`store`.`store_name`, MONTHNAME(date) AS MONTH,`sales`.`sales`來自 company_group、商店、銷售其中`company_group`.`company.id`=`sales`.`company.id`和`store`.`store.id`=`sales`.`store.id`按 company_name,store_name, 'MONTH' 分組聯(lián)盟選擇`company_group`.`company_name,`store`.`store_name`, MONTHNAME(date) AS MONTH,`wh_sales`.`sales`來自 company_group, store,wh_sales其中`company_group`.`company.id`=`wh_sales`.`company.id`和`store`.`store.id`=`wh_sales`.`store.id`按 company_name,store_name, 'MONTH' 分組

現在如何包含 Table5 以便獲得類似的結果

company_name store_name 月銷售購買company-a store-c 十二月 40000 45000

解決方案

Sales vs Whole &銷售,顯示兩者的購買價格對嗎?試試這個.

選擇`company_group`.`company_name, `store`.`store_name`, MONTHNAME(date) AS MONTH,`sales`.`sales`, `purchase`.`purchase`來自 company_group、商店、銷售、購買其中`company_group`.`company.id`=`sales`.`company.id`和`store`.`store.id`=`sales`.`store.id`按 company_name,store_name, 'MONTH' 分組聯(lián)盟選擇`company_group`.`company_name,`store`.`store_name`, MONTHNAME(date) AS MONTH,`wh_sales`.`sales`, `purchase`.`purchase`來自 company_group、商店、wh_sales、購買其中`company_group`.`company.id`=`wh_sales`.`company.id`和`store`.`store.id`=`wh_sales`.`store.id`按 company_name,store_name, 'MONTH' 分組

purchase.purchase 添加到 SELECT 子句和 purchase TABLE 到 FROM 子句提供對表的 purchase 價格字段的訪問.其中,根據您的投影表的purchase 列是必不可少的AND 最簡單的方法.

my set-up is like this

Table1: company_group - company_id, company_name
Table2: store         - store_id, store_name
Table3: sales         - sales_id, company_id, store_id, date, sales
Table4: wh_sales      - wh_sale_id, company_id, store_id, date, sales

Table5: purchase      - purchase_id, company_id, store_id, date, purchase

Now I am able to get the data for the first four tables using the select and union query, but I can't make out how and which join I should use to get the data for the table5 in the same table

I am using the query for the first four tables like

select `company_group`.`company_name, `store`.`store_name`, MONTHNAME(date) AS MONTH,`sales`.`sales` 
from company_group, store,sales
where `company_group`.`company.id`=`sales`.`company.id`
and `store`.`store.id`=`sales`.`store.id`
group by company_name,store_name, 'MONTH'

UNION

select `company_group`.`company_name, `store`.`store_name`, MONTHNAME(date) AS MONTH,`wh_sales`.`sales`
from company_group, store,wh_sales
where `company_group`.`company.id`=`wh_sales`.`company.id`
and `store`.`store.id`=`wh_sales`.`store.id`
group by company_name,store_name, 'MONTH'

now how can I include the Table5 so that I can get the result like

company_name store_name   month      sales    purchase
company-a     store-c    December    40000    45000

解決方案

Sales vs whole & sales, displaying the purchase price for both right ? Try this one.

select `company_group`.`company_name, `store`.`store_name`, MONTHNAME(date) AS MONTH,`sales`.`sales`, `purchase`.`purchase`
from company_group, store,sales, purchase
where `company_group`.`company.id`=`sales`.`company.id`
and `store`.`store.id`=`sales`.`store.id`
group by company_name,store_name, 'MONTH'

UNION

select `company_group`.`company_name, `store`.`store_name`, MONTHNAME(date) AS MONTH,`wh_sales`.`sales`, `purchase`.`purchase`
from company_group, store,wh_sales, purchase
where `company_group`.`company.id`=`wh_sales`.`company.id`
and `store`.`store.id`=`wh_sales`.`store.id`
group by company_name,store_name, 'MONTH'

Adding purchase.purchase to the SELECT clause and the purchase TABLE to the FROM clause provides access to the table's purchase price field. Which, according to your projected table's purchase column is essential AND the simplest method.

這篇關于帶有聯(lián)合和連接的 SQL 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
Convert multiple sub-queries to on join(將多個子查詢轉換為 on join)
How do I get the minute difference between 2 times in T SQL?(如何獲得 T SQL 中 2 次之間的微小差異?)
主站蜘蛛池模板: 亚洲在线观看视频 | 久久精品福利 | 欧美成人精品一区 | 亚洲精品视频免费在线观看 | 久久久久女人精品毛片九一 | 成人中文字幕在线观看 | 成人h视频在线观看 | 日韩精品免费 | 日韩网站免费观看 | 黄色av免费看 | 日韩成人小视频 | 狠狠的干 | 国产视频黄 | 国产精品1区2区 | 国产又粗又猛又黄又爽无遮挡 | 成年人黄色片 | 日韩在线精品视频 | 麻豆成人免费视频 | 欧美成人极品 | 黄色国产网站 | 亚洲精品在 | 国产成人在线观看免费网站 | av色婷婷 | 好吊视频一区二区三区四区 | 四虎8848 | 男女瑟瑟视频 | 国产视频在线观看视频 | 中文字幕国产一区 | 欧洲黄色网 | 欧美综合久久 | 日韩精品在线观看视频 | 亚洲国产成人91精品 | 日韩一区三区 | 国产三级在线看 | 日本中文字幕一区 | av毛片在线播放 | 精品一区二区三区三区 | 亚洲视频在线观看免费 | 黄色大片免费观看 | 男女搞黄网站 | 国产激情一区 |