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

时间:2015-06-26 04:29:54

标签: mysql sql

假设我有一张桌子

int main(int argc, char** argv)
{
   FILE* fpInputFile = NULL; 
   unsigned long ulSize = 0;  // Input File size
   unsigned long ulIteration = 0; 
   unsigned char* ucBuffer; // Buffer data

  if(argc != 2)
  {
   printf("Enter ihe file name \n");
   return -1;
  }
  fpInputFile = fopen(argv[1],"r"); // file open

  if(!fpInputFile){
    fprintf(stderr,"File opening failed");
  }
  fseek(fpInputFile,0,SEEK_END);
  ulSize = ftell(fpInputFile); //current file position
  fseek(fpInputFile,0,SEEK_SET);
  ucBuffer = (unsigned char*)malloc(ulSize); // memory allocation for ucBuffer var
  fread(ucBuffer,1,ulSize,fpInputFile); // Read file
  fclose(fpInputFile); // close the  file
 }

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

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

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

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

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

1 个答案:

答案 0 :(得分:0)

试试这个

Sql fiddle Demo

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