我从下面给出的查询中得到15行,获得的值也显示在下图中
SELECT name_of('2014-04-30') foo_prefix_mnth_date;
对于所有这些值,我还想要一个SELECT * FROM [SS_MatrixLearners]
WHERE ssml_Id_learnercourse=7390 and ssml_id_matrix = 29 and ssml_Id_topic=47
order by SSML_Id_LevelKey, SSML_Id_LevelValue
的值,其SSML_CompletedByUserName
列中包含最新日期。
请帮助我如何获得这个价值。仅供参考我在使用c#
答案 0 :(得分:0)
我想出了以下解决方案。
SELECT * into #temp FROM (SELECT * FROM [SS_MatrixLearners] ORDER BY SSML_ID_LevelKey,SSML_Id_LevelValue)as rn FROM [SS_MatrixLearners]其中ssml_Id_learnercourse = 7390和ssml_id_matrix = 29且ssml_Id_topic = 47)t 在哪里rn = 1 更新#temp SET SSML_CompletedByUserName =(选择前1个ISNULL(SSML_CompletedByUserName,'') 来自[SS_MatrixLearners] WHERE ssml_Id_learnercourse = 7390和ssml_id_matrix = 29和ssml_Id_topic = 47 按SSML_CompletionDate desc排序 ) SELECT * from #temp order by SSML_Id_LevelKey,SSML_Id_LevelValue DROP table #temp
如果可以编写一些优化查询,那就太好了。