Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何为每个帐户获取一条记录?_Sql - Fatal编程技术网

Sql 如何为每个帐户获取一条记录?

Sql 如何为每个帐户获取一条记录?,sql,Sql,我有一个问题: select memo_account ,flags_3,SUFFIX,date FROM MEMO left join daily on daily.ACCOUNT= memo.memo_account where flags_3 = 1 and suffix in (08,00) and memo_number =3333 我得到了两个表中的帐户。 我得到的结果在两行为每个帐户的基础上后缀是00或08 我怎样才能让账户只显示一次呢 后缀取决于

我有一个问题:

select memo_account ,flags_3,SUFFIX,date
   FROM MEMO
   left join daily on daily.ACCOUNT= memo.memo_account
   where flags_3  = 1 and suffix in (08,00)  
   and memo_number  =3333
我得到了两个表中的帐户。 我得到的结果在两行为每个帐户的基础上后缀是00或08

我怎样才能让账户只显示一次呢 后缀取决于一行是00还是08

例如:

备忘录账户后缀00后缀08日期

我犯了一个错误


您还有一个日期,因此如果同一个备忘账户有不同的日期,您将获得一些额外的行,以确保:您想要的是返回后缀的第一个匹配项?或者任何后缀,只要它只有一个?
select memo_account, 
       max(case when SUFFIX = '00' then '00' else null end) as suff00, 
       max(case when SUFFIX = '08' then '08' else null end) as suff08, 
       date
   FROM MEMO
   left join daily on daily.ACCOUNT= memo.memo_account
   where flag_3  = 1 and suffix in (08,00)  
   and memo_number  =3333
group by memo_account, date