【发布时间】:2018-04-13 09:12:17
【问题描述】:
<table>
<tr>
<th>name</th>
<th>sum(value)</th>
</tr>
<tr>
<td>null</td>
<td>85</td>
</tr>
<tr>
<td>arun</td>
<td>74</td>
</tr>
<tr>
<td>dhin</td>
<td>55</td>
</tr>
</table>
我有一个类似上面的表格数据。我希望根据 sum(value) desc 对项目进行排序,如果名称为 null,则必须最后显示。如何在mysql中编写查询
我的查询是 SELECT p.class,p.buyref,p.no_of_mat_id,p.tot_cos from (select a.class,group_concat(distinct a.buyref SEPARATOR '","' ) as buyref,count(*) as no_of_mat_id,sum(tc) as tot_cos from (select a.class,a.buyref,sum(b.total_cost) as tc from (SELECT distinct a.class,b.buyref FROM material_master a join rxml_reference b on a .cat_id=b.cat_id where a.language='0161-1#LG-000001#1' and b.property='BUYER REFERENCE' and b.buyref'' and b.buyref in ("E268200006"," E570500008","E330010072","1274266","1257657","1216933","1275795","1269085","1216931","1257656","1213833","5066725","1275794","5067252" ,"1257658","1236240","1274249","1213824","1275797","5067664","1236239","1248625","1275796","5066724","5065949","1213989"," 1216932","1257659","1227545","1280565","1280549","1213829","1264792","1280550","1280551","1216943","1249846","1210250","1282003" ,"1248620","5065948","1213830","1216942","1210217","1210247","1279855","1280567","1280553","1210292","1281546","1213846"," 1238253","1210323","1264791","50656 10","1217304","1216973","1271479","1285240","1217303","5063937","5063934","1285241","1238255","1280552","1280566","1292638" ,"5075432","1292635","1293721","1258418","1290188","5071130","1292061","1258417","1292634","1292631","1292632","1292633"," 1292639","1292060","5071580","1293251","5075431","1292597","36066","1268083","1219900","49194","46646","1272051","48743" ,"1219891","49604","41693","1247650","1241850","41728","49588","1258736","44917","1219898","1266629","39660"," 1267486","1270445","1222352","1259901","36074","1272388","1275153","1240833","1237806","46645","1219897","1271400","1272385" ,"41066","36073","1244303","1241848","41730","1220612","45332","41565","49204","1244246","45329","1272384"," 1222919","1231947","1225515","1272052","1271399","49664","46118","1241847","49691","1219899","1273498","52919","46350" ,"49201","1272750","1237807","29632","1220800","36481","41709","1276924","40133","36062","36268","49684"," 1273492","1276923","36302","1281374","49603","1219892","49480"))在 a.buyref=b.item 上的 final_transaction b 中,其中 b.accounting_date >= '2014-1-01 00:00:00' 和 b.accounting_date
【问题讨论】:
-
也许显示你正在使用的 mysql 表?
-
如果您的问题是“如何在 MySQL 中编写查询?”那么答案是:这不是一个免费的编程课程网站,去看看一些教程。但我想你的问题写得不好,你问“这样做的查询是什么?”那么答案是:这个网站不是来做你的工作的,提供你尝试过的东西以及你认为它应该工作的原因以及你认为它不工作的原因。
标签: mysql sql-order-by