gpt4 book ai didi

mysql - 在 ColdFusion 查询中连接表

转载 作者:行者123 更新时间:2023-11-29 04:17:09 24 4
gpt4 key购买 nike

我正在执行两个查询,以根据同一数据库中两个表的数据构建一个表。我现在拥有的代码在下面,但我知道我这样做会造成不必要的负担。我一直在尝试加入表格以获得相同的结果,但没有运气。有什么意见吗?

<cfquery name="GetWeekends">
SELECT id, weekend_type, community_id, start_date, end_date, language
FROM _weekends
WHERE weekend_type = 1 and start_date > Now()
ORDER BY start_date ASC
</cfquery>

<cfloop query="GetWeekends">
<cfquery name="GetCommunity">
SELECT community_id, location, language, state, country
FROM _communities
WHERE community_id = #getweekends.community_id#
</cfquery>
<tr>
<td>#DateFormat(start_date, "mm/dd/yyyy")#</td>
<td>#GetComm.location#</td>
<td>#GetComm.state#</td>
<td>#GetComm.country#</td>
<td>#GetComm.language#</td>
</tr>
</cfloop>

最佳答案

数据库连接非常基础。您最好自行了解它们。

无论如何,看起来您想做这样的事情:

<cfquery name="GetWeekends">
SELECT w.id, w.weekend_type, w.community_id, w.start_date, w.end_date,
w.language,
c.community_id, c.location, c.language, c.state, c.country
FROM _weekends w
INNER JOIN _communities c
ON w.community_id=c.community_id
WHERE w.weekend_type = 1 and w.start_date > Now()
ORDER BY w.start_date ASC
</cfquery>

关于mysql - 在 ColdFusion 查询中连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39021120/

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