0

我有 2 张桌子,这是我的小提琴https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=7009f83d39d688e38aceb781b7fdc903

CREATE TABLE users (
  ID int(10) PRIMARY KEY NOT NULL,
  email  varchar(255));
  
CREATE TABLE order_match_detail (ID int(10) PRIMARY KEY NOT NULL,
createdBy int(11),
price decimal(10,2));


INSERT INTO users(ID, email)
SELECT 1, 'testing1@gmail.com' UNION ALL
SELECT 2, 'testing2@gmail.com' UNION ALL
SELECT 3, 'testing3@gmail.com' UNION ALL
SELECT 4, 'testing1@gmail.com' UNION ALL
SELECT 5, 'testing3@gmail.com';

INSERT INTO order_match_detail (ID, createdby, price)
SELECT 1, 1, 2000 UNION ALL
SELECT 2, 1, 2000 UNION ALL
SELECT 3, 2, 2000 UNION ALL
SELECT 4, 2, 3000;

select * from users;
select * from order_match_detail;




with users.id = order_match_detail.createdby

我想通过此查询找出具有相同电子邮件的 users_id

SELECT * FROM users INNER JOIN(
  SELECT email FROM users GROUP BY email HAVING COUNT(email) > 1 order by email)
  temp ON users.email = temp.email;

在我进行此查询后,我想将每个 users_id 与上面的相同电子邮件分开,在上面进行交易,而不是根据 order_match_detail 表进行交易,没有交易的 users_id 不会出现在 order_match_detail 表中。如何将每个 users_id 分开成为做事务和不做事务

基于小提琴的预期结果

+--------------------------------+-------------------------------+
| users_Id  doing transaction    | users_id not doing transaction|
+--------------------------------+-------------------------------+
|                              1 |                          3    |
|                                |                          4    |
|                                |                          5    |
+--------------------------------+-------------------------------+
4

0 回答 0