gpt4 book ai didi

mysql - 如何合并这两个 MySQL 查询

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:30 25 4
gpt4 key购买 nike

我有 2 个查询,它们几乎完全相同。

查询#1:

SELECT 
cman_code, cman_name
FROM
capder
JOIN
caprange ON capder.cder_rancode = caprange.cran_code
JOIN
capman ON caprange.cran_mantextcode = capman.cman_code
JOIN
capmod ON capder.cder_modcode = capmod.cmod_code
JOIN
nvdtechnical ON nvdtechnical.TECH_Id = capder.cder_ID
JOIN
nvddictionarytechnical ON nvddictionarytechnical.DT_TechCode = nvdtechnical.TECH_TechCode
JOIN
nvddictionarycategory ON nvddictionarycategory.DC_CatCode = nvddictionarytechnical.DT_CatCode
JOIN
nvdmodelyear ON capder.cder_ID = MY_Id
AND nvddictionarytechnical.DT_TechCode = 67
AND nvdtechnical.TECH_Value_Float < '100'
AND nvdtechnical.TECH_Value_Float != 0
AND cder_transmission = 'M'
AND cman_code IN ('1','140','164','836','869','1283','1333','1925','2193','2514','4256','4537','4721','4835','5088','5171','5182','5238','5261','5509','6058','6425','7104','7983','8083','8219','9909','10172','10251','10383','10519','10968','12243','12764','14786','15155','21223','22439','44394','47841')
AND (cmod_discontinued=0 OR cmod_discontinued=2015)
AND cder_discontinued = '0000-00-00 00:00:00'
GROUP BY
cman_code
ORDER BY
cman_name DESC

查询#2:

SELECT 
cman_code, cman_name
FROM
capder
JOIN
caprange ON capder.cder_rancode = caprange.cran_code
JOIN
capman ON caprange.cran_mantextcode = capman.cman_code
JOIN
capmod ON capder.cder_modcode = capmod.cmod_code
JOIN
nvdtechnical ON nvdtechnical.TECH_Id = capder.cder_ID
JOIN
nvddictionarytechnical ON nvddictionarytechnical.DT_TechCode = nvdtechnical.TECH_TechCode
JOIN
nvddictionarycategory ON nvddictionarycategory.DC_CatCode = nvddictionarytechnical.DT_CatCode
JOIN
nvdmodelyear ON capder.cder_ID = MY_Id
WHERE
nvddictionarytechnical.DT_TechCode = 11
AND nvdtechnical.TECH_Value_Float < 25
AND nvdtechnical.TECH_Value_Float != 0
AND cder_transmission = 'M'
AND cman_code IN ('1','140','164','836','869','1283','1333','1925','2193','2514','4256','4537','4721','4835','5088','5171','5182','5238','5261','5509','6058','6425','7104','7983','8083','8219','9909','10172','10251','10383','10519','10968','12243','12764','14786','15155','21223','22439','44394','47841')
AND (cmod_discontinued=0 OR cmod_discontinued=2015)
AND cder_discontinued = '0000-00-00 00:00:00'
GROUP BY
cman_code
ORDER BY
cman_name DESC

这两个查询都能完美运行并产生我想要的准确结果。

两者之间的唯一区别是 nvddictionarytechnical.**DT_TechCode**nvdtechnical.**TECH_Value_Float**

我无法将它们组合在一起。

TECH_Value_Float - 列包含CO2MPG 值。

我只需要将它们合并到 1 个查询中。

使用这个不起作用:

where 
(
(
nvddictionarytechnical.DT_TechCode = 67
AND nvdtechnical.TECH_Value_Float < '100'
)
or
(
nvddictionarytechnical.DT_TechCode = 11
AND nvdtechnical.TECH_Value_Float < 25
)
)

where 和 or 产生如下结果:

|CO2 | MPG|
-----------
94 | 78 |
378 | 19 |

我需要 MPG 和 CO2 都为真。结果如下:

|CO2 | MPG|
-----------
15 | 18 |
10 | 17 |

专业人士有什么建议吗?我应该只查询 2 个吗?有没有人遇到过这样的问题?这很不寻常吗?

感谢您的帮助。

最佳答案

你试过吗:

where 
(
(
nvddictionarytechnical.DT_TechCode = 67
AND nvdtechnical.TECH_Value_Float < '100'
)
or
(
nvddictionarytechnical.DT_TechCode = 11
AND nvdtechnical.TECH_Value_Float < 25
)
)

关于mysql - 如何合并这两个 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29398837/

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