gpt4 book ai didi

mysql查询左连接和过滤

转载 作者:行者123 更新时间:2023-11-29 21:51:54 24 4
gpt4 key购买 nike

SELECT
TABLE_1.ID,
IF(TABLE_2.show IS NULL,0,1) AS RESULT,
FROM
TABLE_1
LEFT JOIN TABLE_2 ON
TABLE_1.ID=TABLE_2.ID AND DATE(DATE_ADD( TABLE_2.DATE, INTERVAL +10 DAY)) < NOW()
WHERE
TABLE_1.ID='1';

我的问题:table_1.ID=table_2.ID

TABLE_2.DATE = 06-11-2015
NOW = 07-11-2015

if TABLE_2.DATE < NOW() = true (RESULT = 1)

TABLE_2.DATE = 06-11-2015
NOW = 05-11-2015
if TABLE_2.DATE < NOW() = false (RESULT = 0)

but
have TABLE_1.ID
have TABLE_2.ID

i need

1.position "date ok", "table connection ok" = item old

2.position "date off", "table connection ok" = item hidden

3.position "date ok", "tablo connection no" = item new

但不工作:(

最佳答案

SELECT
TABLE_1.ID,
IF(TABLE_2.show IS NULL,0,1) AS RESULT,
FROM
TABLE_1
LEFT JOIN TABLE_2 ON
TABLE_1.ID=TABLE_2.ID AND DATE(DATE_ADD( TABLE_2.DATE, INTERVAL +10 DAY)) < NOW() AND TABLE_2.DATE IS NOT NULL
WHERE
TABLE_1.ID='1';

1.position "date ok", "table connection ok" = item old (it's work)

2.position "date off", "table connection ok" = item hidden (it's not work)

3.position "date ok", "tablo connection no" = item new (it's work)

我的问题是2.位置

关于mysql查询左连接和过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33559085/

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