gpt4 book ai didi

mysql - mysql中合并表

转载 作者:行者123 更新时间:2023-11-30 00:21:53 25 4
gpt4 key购买 nike

这里我遇到了连接表的问题,所以我从表 a.KOT_Items 创建了两列,例如 mon,monthnames ,现在我必须结合表 中的更多内容Item_Master b,KOT_Main c,Outlet d,Category_Master e,Department_Master f但没有结果我是mysql的新手可以有人帮忙解决这个问题。

查询::

SELECT a.mon,
a.monthnames,
d.Outlet_Name,
e.category_Name,
f.Department_Name,
b.Item_Name,
a.Item_Qty,
a.Net_amount+a.Item_tax1 AS NetAmount,
a.Tran_Date
FROM
(SELECT 1 AS mon,
'Jan' AS monthnames
UNION SELECT 2,
'Feb'
UNION SELECT 3,
'Mar'
UNION SELECT 4,
'Apr'
UNION SELECT 5,
'May'
UNION SELECT 6,
'jun'
UNION SELECT 7,
'july'
UNION SELECT 8,
'Aug'
UNION SELECT 9,
'Sep'
UNION SELECT 10,
'Oct'
UNION SELECT 11,
'NoV'
UNION SELECT 12,
'Dec') AS months
LEFT JOIN a.KOT_Items AS i ON months.mon = MONTH(i.tran_date),
Item_Master b,
KOT_Main c,
Outlet d,
Category_Master e,
Department_Master f

WHERE
AND a.Main_Item_Code=b.Item_Code
AND e.Category_Code=b.Category_Code
AND e.Category_Code =f.Category_Code
AND d.Outlet_id = c.outlet_id
AND a.ref_no=c.ref_no
GROUP BY a.Bill_No

异常(exception)结果为

mon ||monthname || outlet_name ||  category_Name || Department_Name || Item_Name

更新::

mon monthnames Outlet_Name      netamount

4 Apr MEXICAN AMIGOS 1
4 Apr MEXICAN AMIGOS 100
4 Apr MEXICAN AMIGOS 150
4 Apr MEXICAN AMIGOS 1500
4 Apr MEXICAN AMIGOS
4 Apr MEXICAN AMIGOS
4 Apr MEXICAN AMIGOS
4 Apr MEXICAN AMIGOS
4 Apr MEXICAN AMIGOS
1 jan
2 feb
3 mar
5 may
6 june
7 july
8 Aug
9 Sep
10 Oct
11 nov
12 Dec

最佳答案

这样的东西应该有效

SELECT m.mon, m.monthnames, d.Outlet_Name, e.category_Name, f.Department_Name, b.Item_Name, SUM(a.Item_Qty) AS Qty, SUM(a.Net_amount+a.Item_tax1) AS NetAmount
FROM KOT_Items a,
(SELECT 1 AS Mon, 'Jan' AS monthnames
UNION
SELECT 2 AS Mon, 'Feb' AS monthnames
UNION
SELECT 3 AS Mon, 'Mar' AS monthnames
UNION
SELECT 4 AS Mon, 'Apr' AS monthnames -- Complete Rest
) AS m,
Item_Master b,
KOT_Main c,
Outlet d,
Category_Master e,
Department_Master f
WHERE MONTH(a.tran_date) = m.Mon
AND a.Main_Item_Code=b.Item_Code
AND e.Category_Code=b.Category_Code
AND e.Category_Code =f.Category_Code
AND d.Outlet_id = c.outlet_id
AND a.ref_no=c.ref_no
GROUP BY m.mon, m.monthnames, d.Outlet_Name, e.category_Name, f.Department_Name, b.Item_Name

关于mysql - mysql中合并表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23166850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com