gpt4 book ai didi

MYSQL LIKE IN/匹配子字符串

转载 作者:行者123 更新时间:2023-11-29 11:00:34 26 4
gpt4 key购买 nike

我有以下两条语句,并且希望仅在一条语句中得到它。那可能吗?

声明一,获取最近 2 天的内容:

SELECT  
c.ID SUBTAG
FROM
`content` c,
posts p
WHERE
c.id = p.id_content AND
from_unixtime(p.scheduled) BETWEEN TIMESTAMPADD(DAY,-2,now()) AND from_unixtime(UNIX_TIMESTAMP(NOW()))
ORDER BY from_unixtime(p.scheduled)

使用 c.id,我需要从订单中获取总和(数量)。像这样:

 SELECT 
sum(Qty) Bestellungen,
SUBTAG
FROM
Orders
WHERE SubTag Like '%c.id%'
GROUP BY SubTag

在表订单中,列子标签并不完全具有 c.id。它只是专栏的一部分。这就是为什么我需要这样的东西!表订单中的子标签类似于 132_子标签_kjsdf4382。

表订单看起来像:

Date_           Price   Qty     SubTag  
2017-02-20 14.98 1 b1a8cc_2_qgsGairwtape
2017-02-20 14.98 1 b1a8cc_3_qgdfgdirwtape

帖子看起来像:

ID      id_content      scheduled           ad_active   posted 
3015 82 1487754540 0 1

内容如下:

ascsubid    ID              
b1a8cc 82

查询结果应如下所示:

SubTag   Orders
b1a8cc 2

最佳答案

类似这样的事情吗?

SELECT 
sum(Qty) Bestellungen,
SUBTAG
FROM
Orders
WHERE SubTag in
(SELECT c.ID
FROM `content` c, posts p
WHERE c.id = p.id_content AND
from_unixtime(p.scheduled) BETWEEN TIMESTAMPADD(DAY,-2,now()) AND
from_unixtime(UNIX_TIMESTAMP(NOW()))
and c.id Like '%c.id%')
GROUP BY SubTag;

关于MYSQL LIKE IN/匹配子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42364872/

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