我的表中有2列table_num,id,名为medium
我希望基于DESC的id序列来回显table_num而不重复。
我正在使用此查询获得结果4,2,7,5,3但我想要的结果是4,5,7,2,3
check this image for tables structure
SELECT DISTINCT table_num FROM medium ORDER BY id DESC
答案 0 :(得分:1)
您描述的顺序是升序,而不是降序:
public static String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
}
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:",b));
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
}
return "02:00:00:00:00:00";}
答案 1 :(得分:0)
执行GROUP BY
,按每个table_num的最大ID按降序排序:
select table_num
from medium
group by table_num
order by max(id) desc
要更好地了解其工作原理,请将max(id)
添加到选择列表中:
select table_num, max(id) as max_id
from medium
group by table_num
order by max_id desc