回答

收藏

将一列优先于另一列

技术问答 技术问答 168 人阅读 | 0 人回复 | 2023-09-12

DB提琴! w) y1 |: y6 ]% P8 `
CREATE TABLE logistics (    id int primary key,   campaign VARCHAR   quantity_offered VARCHAR   quantity_ordered VARCHAR    quantity_delivered VARCHAR   quantity_recorded VARCHAR   quantity_completed VARCHAR(255));INSERT INTO logistics(id,campaign,quantity_offered,quantity_ordered,quantity_delivered,quantity_recorded,quantity_completed)VALUES ("1","C001","500","450","465","462","465"),("2","C002","700","570",NULL,NULL,NULL),("3","C003","600","610","605","602",NULL),("4","C004","300",NULL,NULL,NULL,NULL),("5","C005","400","425",NULL,NULL,NULL),("6","C006","900","870","868",NULL,NULL),("7","C007","350","360","372","375","390"),("8","C008","250","290",NULL,NULL,NULL);在上表中我campaigns不同于它们对应的不同quantities。5 G  J6 f6 _. M+ b. N
的quantities不同的填写方法columns。" E; a0 z0 X; w& E9 q, n$ `
现在,我想根据以下层次结构获得每个 最新可用数量campaign:
% N1 ?$ }. [6 xquantity_completed > quantity_recorded > quantity_delivered > quantity_ordered > quantity_offered结果如下:! V& I* |1 R8 H, M; R
Campaign      QuantityC001             46555                C          570005C003          C           30000C5005            42555C            8700C           3900C008             2900002我需要执行什么查询?* t/ P# J- J+ x# P5 `! o7 }/ G
                                                                # f  w  H2 g) `' |0 R, s4 ]2 f
    解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则