douxun2018 2014-10-08 09:52
浏览 205


My current projects consist of Registration of families of different areas in a City. i want to Generate a Unique ID to each families in which i need this ID for another part of this project.Each area in the city have already a unique number eg: 855, 856, 857,etc

So my plan is to generate unique Family ID by combining unique number already have + text "FM"+ number (1,2,3....) and store this uid to DB along with family details.

For eg (Area-855): 855FM1, 855FM2, 855FM3....

if the last registered family uid is 855FM40 , then next family uid must be 855FM41. so i want to fetch the largest value from uid field. in above eg:, largest is 855FM41. how i do this. ?

i have simple logic that fetch all uid, then split it after "FM". then find largest ,etc

How i solve this problem.? is there any simple way other than this.?

  • 写回答

2条回答 默认 最新

  • dongxia19772008 2014-10-08 09:56

    Using ORDER command you can sort your data by ordering of one column ascending or descending.

    so first we order FamilyID column descending (in sql we use DESC) and then we get the first row which has biggest FamilyID value using "LIMIT 0,1" command

    Try this:

    SELECT * FROM families ORDER BY FamilyID DESC LIMIT 0, 1
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥50 swiftui @query 报错
  • ¥50 怎么解决刷卡或扫码后,点击软件输入框,win10屏幕键盘不会自动弹出的问题
  • ¥15 如何使用arcgispro的训练深度模型,发现water和nowater精度为0?(相关搜索:深度学习)
  • ¥20 matlab作业不太懂呀有问题能给个代码吗
  • ¥15 自制电路图为何无法驱动ESP01S?
  • ¥15 前端加access数据库
  • ¥15 ARCGIS 多值提取到点 ERROR 999999
  • ¥15 mysql异常断电, [MY-011971] [InnoDB]
  • ¥15 uni.onBluetoothDeviceFound熄屏不运行
  • ¥15 求PHDA糖尿病并发症数据集,有偿