Finding/searching for missing values in MySQL

前端 未结 5 1099
清歌不尽
清歌不尽 2021-01-16 14:04

I am using MySQL and have a table called sales. Its primary key is sales_id.

-------------------------------------
sales_id | invo         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 14:18

    set @suggest_invoice:=147;
    
    select 
      sales_id, 
      invoice_id,
      @suggest_invoice:=@suggest_invoice+1,
      if(invoice_id=@suggest_invoice, 0, 1) as missing_invoice
    from sales
    order by sales_id;
    

    I guess you almost getting all the records except the first two with missing_invoice=1

提交回复
热议问题