繁体   English   中英

仅显示在下一条记录中具有相同值的第一列

[英]Show only the first column which has the same value on next record

假设我有一张桌子

name ----------------------- phone ------------------------ address

Aldi ----------------------- 021345 ----------------------- Bogor

Aldi ------------------------021345 ----------------------- Jakarta

John ------------------------034566 ----------------------- Depok

如果在下一记录中具有相同的值,如何仅显示第一列? 结果可能看起来像:

name ----------------------- phone ------------------------ address

Aldi ----------------------- 021345 ----------------------- Bogor

----------------------------------------------------------- Jakarta

John ----------------------- 034566 ----------------------- Depok

尝试这个

SQL小提琴演示

select t1.id,
case when t1.name = t2.name and t1.phone = t2.phone
then
'-'
else
t1.name
end as name,
case when t1.name = t2.name and t1.phone = t2.phone
then
'-'
else
t1.phone
end as phone,t1.address from test t1 left join test t2 on t2.id = t1.id-1
order by t1.id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM