gpt4 book ai didi

mysql 联合全部不工作

转载 作者:行者123 更新时间:2023-11-29 13:14:04 28 4
gpt4 key购买 nike

将下面的 MySQL 代码与 ORDER BY 一起使用不起作用。我搜索并尝试了各种版本的代码(UNION、UNION ALL、带括号、不带括号、一个 SELECT 包装所有 SELECT UNION ALL 然后对其进行排序) - 没有运气。还有其他建议吗?

        (SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='res' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM res_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='con' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM con_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='mul' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM mul_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='rnt' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM rnt_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='ici' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM ici_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='far' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM far_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

UNION ALL

(SELECT FORMAT(lt.`rets_111`, 0) AS 'ListPrice', lt.`rets_128` AS 'MlsNumber', lt.`rets_13` AS 'Address', lt.`rets_2044` AS 'PublicRemarks', lt.`rets_sysid`, @real_estate_type:='lot' AS real_estate_type,
lt.`rets_2362` AS 'OpenHouseDate1', lt.`rets_2364` AS 'OpenHouseStartTime1', lt.`rets_2366` AS 'OpenHouseEndTime1', lt.`rets_2370` AS 'DisplayOpenHouse1',
lt.`rets_2372` AS 'OpenHouseDate2', lt.`rets_2374` AS 'OpenHouseStartTime2', lt.`rets_2376` AS 'OpenHouseEndTime2', lt.`rets_2380` AS 'DisplayOpenHouse2'
FROM lot_listings AS lt
WHERE lt.`rets_32` IN ('AGENT1', 'AGENT2') OR lt.`rets_2337` IN ('AGENT1', 'AGENT2') OR lt.`rets_1836` IN ('AGENT1', 'AGENT2'))

ORDER BY 'ListPrice' DESC

最佳答案

这是您的订单:

ORDER BY 'ListPrice' DESC

它按常量字符串排序。试试这个:

ORDER BY ListPrice DESC

并且,将来仅对字符串和日期常量值使用单引号。永远、永远不要用于数据库中事物的名称。

关于mysql 联合全部不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21713875/

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