获取列中显示的所有行具有相同的值

时间:2018-04-05 12:05:11

标签: mysql sql

${DBCPURL}

但是这只会返回每个应该返回10的记录

2 个答案:

答案 0 :(得分:1)

SELECT
   auction_id,
   account_no,
   branch_address 
FROM
   Table1 
   LEFT JOIN
      Table2 
      ON Table1.`aul_id` = Table2.`aul_id` 
WHERE
   Table2.`date` = '2018-03-20' 
   AND Table1.`branch_address` IN 
   (
      SELECT
         Table1.`branch_address` 
      FROM
         Table1 
         LEFT JOIN
            Table2 
            ON Table1.`aul_id` = Table2.`aul_id` 
      WHERE
         Table2.`date` = '2018-03-20' 
      GROUP BY
         Table1.`branch_address` 
      HAVING
         Count(*) >= '10' 
         AND Count(*) <= '10' 
   )

答案 1 :(得分:0)

尝试运行不带子句的查询并检查count(*)值。

你会得到一些答案。下面添加了示例oracle查询。

------------------------------------------ CODE ---- ---------------------------

create table table1(branchaddress varchar2(10), aul_id number);
insert into table1 values('address1', 10);
insert into table1 values('address1', 10);
insert into table1 values('address2', 10);
insert into table1 values('address2', 10);
create table table2(branchaddress varchar2(10),aul_id number );
insert into table2 values('address1', 10);
insert into table2 values('address2', 10);

commit;

SELECT table1.branchaddress, count(*)
FROM Table1, table2
where Table1.branchaddress = Table2.branchaddress(+)
GROUP BY Table1.branchaddress
HAVING Count(*) >= 2 AND Count(*) <= 10