gpt4 book ai didi

mysql - 当其中一个值是 SELECT 语句的结果时,如何使用 COUNT(DISTINCT...)?

转载 作者:行者123 更新时间:2023-11-29 06:49:01 24 4
gpt4 key购买 nike

我有一个返回行的 SQL 语句:

SELECT DISTINCT wp_w2bw2c_event.venue_id, 
(SELECT MIN(begin_date)
FROM wp_w2bw2c_event_detail
WHERE wp_w2bw2c_event_detail.event_id = wp_w2bw2c_event.id)
as begin_date,
wp_w2bw2c_event.id as event_id
FROM wp_w2bw2c_event
INNER JOIN wp_w2bw2c_venue
ON wp_w2bw2c_venue.id = wp_w2bw2c_event.venue_id
INNER JOIN wp_w2bw2c_event_detail
ON wp_w2bw2c_event_detail.event_id = wp_w2bw2c_event.id
WHERE wp_w2bw2c_venue.venue_name LIKE '%ironworks%'
OR artist_name LIKE '%ironworks%'
OR event_title LIKE '%ironworks%'
OR event_detail_title LIKE '%ironworks%'
ORDER BY wp_w2bw2c_event.venue_id, begin_date, event_id

如果我尝试使用 COUNT 函数仅计算行数,则会收到 SQL 数据库错误

SELECT COUNT(DISTINCT wp_w2bw2c_event.venue_id, 
(SELECT MIN(begin_date)
FROM wp_w2bw2c_event_detail
WHERE wp_w2bw2c_event_detail.event_id = wp_w2bw2c_event.id)
as begin_date,
wp_w2bw2c_event.id as event_id)
FROM wp_w2bw2c_event
INNER JOIN wp_w2bw2c_venue
ON wp_w2bw2c_venue.id = wp_w2bw2c_event.venue_id
INNER JOIN wp_w2bw2c_event_detail
ON wp_w2bw2c_event_detail.event_id = wp_w2bw2c_event.id
WHERE wp_w2bw2c_venue.venue_name LIKE '%ironworks%'
OR artist_name LIKE '%ironworks%'
OR event_title LIKE '%ironworks%'
OR event_detail_title LIKE '%ironworks%'

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'as begin_date,
wp_w2bw2c_event.id as event_id
FROM wp_w2bw2c_event
INNE' at line 5

如何更改 SQL 以便 COUNT(DISTINCT... 处理 SELECT 的结果?

最佳答案

您的查询返回不同的行。因此,您所要做的就是计算该查询的结果:

select count(*) from (your query) q;

关于mysql - 当其中一个值是 SELECT 语句的结果时,如何使用 COUNT(DISTINCT...)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48245330/

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