Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: no overload satisfies `eq(String NULL, UInt64 NULL) (found by chatGPT) #13776

Closed
xudong963 opened this issue Nov 21, 2023 · 0 comments · Fixed by #13782
Closed

Bug: no overload satisfies `eq(String NULL, UInt64 NULL) (found by chatGPT) #13776

xudong963 opened this issue Nov 21, 2023 · 0 comments · Fixed by #13782
Assignees

Comments

@xudong963
Copy link
Member

Summary

CREATE TABLE customers (
  customer_id INT ,
  name VARCHAR(255),
  region VARCHAR(255),
  industry VARCHAR(255) NULL
);
CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  customer_id INT,
  order_date DATE,
);
CREATE TABLE products (
  product_id INT,
  name VARCHAR(255),
  category VARCHAR(255),
  price FLOAT
);
CREATE TABLE order_details (
  order_id INT,
  product_id INT,
  quantity INT
);
SELECT 
  c.name,
  c.region,
  (SELECT category
   FROM (
     SELECT p.category, COUNT(*) as order_count
     FROM orders o
     JOIN order_details od ON o.order_id = od.order_id
     JOIN products p ON od.product_id = p.product_id
     WHERE o.customer_id = c.customer_id
     GROUP BY p.category
     ORDER BY order_count DESC
     LIMIT 1
   ) as most_ordered_category
  ) as favorite_category,
  (SELECT AVG(price)
   FROM products
   WHERE category = (
     SELECT category
     FROM (
       SELECT p.category
       FROM orders o
       JOIN order_details od ON o.order_id = od.order_id
       JOIN products p ON od.product_id = p.product_id
       WHERE o.customer_id = c.customer_id
       GROUP BY p.category
       ORDER BY COUNT(*) DESC
       LIMIT 1
     ) as sub_query
   )
  ) as avg_price_of_favorite_category
FROM customers c
WHERE c.region = '特定地区';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant