它的别名选择从一个子查询的列生成错误

问题描述 投票:-1回答:1

特别是,我想它的别名来选择子查询列,但这会产生错误。我指的是这条线尤其是从下面的完整的查询:

    WHERE id NOT IN (SELECT x.minid (SELECT p.post_title, MIN(m.id) as minid, m.meta_value
...) as x );
create table wp_posts (
  ID integer primary key auto_increment,
  post_title varchar(30),
  post_type varchar(30)
);
create table wp_postmeta (
  ID integer primary key auto_increment,
  post_id integer,
  meta_key varchar(30) not null default '_regular_price',
  meta_value integer not null
);
insert into wp_posts (post_title, post_type) values
('Apple Pie','Product'),
('French Toast','Product'),
('Shepards Pie','Product'),
('Jam Pie','Product'),
('Jam Pie','Product'),
('Plate','Not a Product'),
('Bucket','Not a Product'),
('Chequebook','Not a Product'),
('French Toast','Product'),
('French Toast','Product'),
('Banana','Product'),
('Banana','Product'),
('Banana','Product');
insert into wp_postmeta (post_id, meta_value) values
(1,10),
(2,5),
(3,9),
(4,8),
(5,11),
(6,12),
(7,10),
(8,6),
(9,1),
(10,1),
(11,7),
(12,2),
(13,2);
-- Deleting all duplicate products in wp_posts table 
DELETE FROM wp_posts 
WHERE id NOT IN (SELECT x.minid (SELECT p.post_title, MIN(m.id) as minid, m.meta_value
FROM 
    wp_postmeta m
    INNER JOIN wp_posts p 
        ON  p.id = m.post_id
        AND p.post_type = 'Product' 
WHERE 
    m.meta_key = '_regular_price'
    AND NOT EXISTS (
        SELECT 1
        FROM 
            wp_postmeta m1
            INNER JOIN wp_posts p1
                ON  p1.id = m1.post_id
                AND p1.post_type = 'Product'
        WHERE 
            m1.meta_key = '_regular_price'
            AND p1.post_title = p.post_title
            AND m1.meta_value < m.meta_value
     )
 GROUP BY p.post_title, m.meta_value) as x
 );
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 'SELECT p.post_title, MIN(m.id) as minid, m.meta_value
FROM 
    wp_postmeta m
  ' at line 3

分贝<>小提琴here

如果它不能因为语法规则来完成,我怎么会选择聚合列MIN(m.id)

mysql syntax mariadb
1个回答
1
投票

我想你已经从关键字的子查询的一失手。

WHERE ID NOT IN(选择从x.minid(SELECT p.post_title,MIN(m.id)作为minid,m.meta_value ...)为x);

© www.soinside.com 2019 - 2024. All rights reserved.