duanchigeng4313 2014-12-22 11:06
浏览 51

从mysql数据库中的每个值获取最后的结果

I have an array with a list of horses in it.

I want to be able to go through that array and pull each of the horses last result.

Currently my code looks like the following:

select count(*),Horse,Place from horsesrp where Horse In (".$horsearray.")")

How would i amend this so that only the horses last result in the array was shown.

below is the output on my array

Array ( [0] => Sky Watch [1] => Sunny Ledgend [2] => Jupiter Rex [3] => Storm Alert [4] => Alanjou [5] => Strike Fast [6] => Mister Grez [7] => Stone Light [8] => Free World [9] => Humbel Ben [10] => Honour A Promise [11] => Sassanova [12] => Binowagh Bay [13] => Lady Garvagh [14] => Ovilia [15] => Agent Fedora [16] => Dazzling Rita [17] => Moving Waves [18] => Pandy Wells [19] => Frank N Fair [20] => Ruby Valentine [21] => Pennies And Pounds [22] => Never Never [23] => Bertie Moon [24] => Definite Future [25] => If It Be Your Will [26] => Kapstadt [27] => Kayf Blanco [28] => Neworld [29] => Polvere D'oro [30] => Restraint of Trade [31] => Broome Lane [32] => Fine Lily [33] => Pembridge [34] => Capard King [35] => Central School [36] => Coologue [37] => Ma du Fou [38] => Quintano [39] => The Mobb [40] => The Western Force [41] => Youngdocgallagher [42] => Tara Mac [43] => No Principles [44] => Raid Stane [45] => Elton Fox [46] => Minella Bliss [47] => Midnight Dove [48] => Saga de Tercey [49] => Iktiview [50] => Nordic Nymph [51] => Do Be Dashing [52] => Tantalized [53] => Apache Chief [54] => Black Jack Rover [55] => Charlie Cook [56] => Freddie Bear [57] => Rambo [58] => The Late Shift [59] => Tropical Sunshine [60] => Western Xpress [61] => Vitarra [62] => Azure Amour [63] => My Mistress [64] => Royal Roslea [65] => Beach Plaza [66] => Dat Il Do [67] => Surelookit [68] => Bollywood Dream [69] => Dutch Fredie G [70] => Suffolk Sky [71] => Trikasana [72] => Lettuce Snow [73] => Tommy's Secret [74] => Freddy With A Y [75] => Starlight Symphony [76] => Embankment [77] => Gracious George [78] => Presumido [79] => Until Midnight [80] => Gannicus [81] => Next Stop [82] => Woodbridge [83] => Elusive Ellen [84] => Evident [85] => Bobby Benton [86] => Kuwait Star [87] => Ruban [88] => Senator Matt [89] => Strictly The One [90] => Belahodood [91] => Filosofo [92] => Made With Love [93] => Silver Secret [94] => Ladyhawk [95] => Tiger Stone [96] => Thane of Cawdor [97] => Maison Brillet [98] => Idol Deputy [99] => Takeitfromalady [100] => Mcbirney [101] => Bennelong [102] => Eurato [103] => Day Of The Eagle [104] => Fair Comment [105] => Gracefilly [106] => Softly She Treads [107] => Munsarim [108] => Bowsers Bold [109] => Eastward Ho [110] => Burning Blaze [111] => Trader Jack [112] => Brigliadoro [113] => Midnight Rider [114] => Good Luck Charm [115] => Ertikaan [116] => Palace Moon [117] => Don't Be [118] => Toga Tiger [119] => Footstepsintherain [120] => Polar Kite [121] => Conry [122] => Sheikh The Reins [123] => Whaleweigh Station [124] => Light From Mars [125] => Strategic Force [126] => Lady Brigid [127] => Secret Asset [128] => Nonno Giulio [129] => Head Space [130] => Time And Place [131] => Secret Millionaire [132] => Drive On [133] => Clockmaker [134] => Angus Glens [135] => Dont Take Me Alive [136] => Greeleys Love [137] => Arashi [138] => Addazero [139] => Montaff [140] => Guards Chapel [141] => Leyland [142] => Artisan [143] => Golden Bird [144] => Sparkling Ice [145] => Rookery [146] => Haines [147] => Ballyfarsoon [148] => Bahango [149] => Kyrenia Castle [150] => Bahama Blue [151] => Desert Apostle [152] => Vivre La Reve [153] => Thataboy [154] => Royal Acquisition [155] => Pensax Lad [156] => Captain Whoosh [157] => Scoreline [158] => West Coast Dream [159] => Profile Star [160] => Pearl Noir [161] => Bilash [162] => Black Dave [163] => Argent Touch [164] => Mr Mo Jo [165] => Island Express [166] => Sir Billy Wright [167] => Summersault [168] => Windy Miller [169] => Zat Be Zat [170] => Nelson's Pride [171] => Princess Rose [172] => Zaria [173] => Shyron [174] => Monsea [175] => Silverware [176] => Corporal Maddox [177] => Mr Bossy Boots [178] => Loyalty [179] => Smokethatthunders [180] => Order Of Service [181] => Ace Master [182] => Rasaman [183] => Beedee [184] => Rich Again [185] => Ruggero [186] => Tukitinyasok [187] => Keeper's Ring [188] => Catching Zeds [189] => Pipers Piping [190] => Tsarglas [191] => Key To Your Heart [192] => Katmai River [193] => Spokesperson [194] => Navajo Dream [195] => Courtezan [196] => Ambella [197] => Russian Ice [198] => Boboli Gardens [199] => Sarlat [200] => Look Here's Al [201] => Postillion [202] => Cherry Tiger [203] => Celestial Dawn [204] => Previous Acclaim [205] => Dutch Lady Roseane [206] => L'inganno Felice [207] => Take Two [208] => A Little Bit Dusty [209] => Amazing Star [210] => Aneedh [211] => Dialogue [212] => Gabrial The Duke [213] => Swift Cedar [214] => Menelik [215] => Gilmer [216] => Sheriff Of Nawton [217] => Dansili Dutch [218] => Disclosure [219] => Royal Trooper [220] => Helmsley Flyer [221] => Taroum [222] => Reality Show [223] => Pim Street [224] => Cropley [225] => Dhaular Dhar [226] => Qibtee [227] => Uganda Glory [228] => Master Of Song [229] => Cabuchon [230] => Percys Princess ) 

the database holds results from horse races so i want to get each horses last result

running the following sql command would produce the following: "select Place, Horse from horsesrp where Horse In (".$horsearray.")"

Haines Rich Again Uganda Glory Rich Again Sarlat Rich Again Gracious George Lady Brigid Rich Again Smokethatthunders Dialogue L'Inganno Felice Pearl Noir

as cna be seen rich again is shown several times and i only want to get the last result (1 result only)

I have tried "select Place, Horse from horsesrp where Horse In (".$horsearray.") limit 1" but that just returns the first horse Haines

  • 写回答

1条回答 默认 最新

  • doulan9287 2014-12-24 14:43
    关注

    I think I understand what you are trying to do...

    Select (select Place from horserp as rp where rp.Horse = Horse Order By id DESC LIMIT 1) as place, Horse From horsesrp Horse In (".$horsearray.")")

    I am hoping that id is your Primary Key and its an integer. Should work for a DateTime or Date column as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab