sql packet takes the value of the most

 

the Create the Table mobilelog (
  the above mentioned id int Primary Key AUTO_INCREMENT, / * increment the above mentioned id * /
  Mobile VARCHAR (26), / * phone number * /
  log VARCHAR (55), / * log * /
  CreateTime datetime / * Create a time * /
) ;

Each phone number to obtain the latest log information

First get all the latest numbers id, here too with the need to distinguish each log id, because createtime may be repeated.

select max(id) from mobilelog group by mobile;

Obtain information by logging id:

select * from mobilelog where id in (select max(id) from mobilelog group by mobile);

Get the latest log information part numbers:

select * from mobilelog where id in

  (select max(id) from mobilelog where mobile in ('15209864032','17209864032')

   group by mobile);

 

Guess you like

Origin www.cnblogs.com/mryangbo/p/11246174.html