将访问查询转换为sql 2012

时间:2015-10-07 12:47:27

标签: sql sql-server access-vba

您好我想在sql中有这个查询如何将其更改为sql one。

from <path_to_your_models> import *
print len(list(contact_info.objects.filter(id = None)))

1 个答案:

答案 0 :(得分:0)

转到http://www.w3schools.com/sql/sql_func_last.asp以获取有关最后和可能的解决方法的详细说明。使用该页面中的信息,我建议您尝试以下代码 -

SELECT Main.ID,
       Main.Name,
       Main.Family,
       Main.Mobile,
       Main.[Import Date],
       Main.Ostan,
       Main.City,
       Main.REP,
       Main.REP1,
       Main.ostan2,
       Main.City2,
       Main.Hospital,
       Main.Expert,
       Main.Status,
       Main.Type,
       Main.Time,
       (SELECT TOP 1 Report.Date
        FROM Report
        ORDER BY Repoort.Date DESC) AS LastOfDate,
       (SELECT TOP 1 NameP
        FROM Report
        ORDER BY NameP DESC) AS LastOfNameP,
       (SELECT TOP 1 NextC
        FROM Report
        ORDER BY NextC DESC) AS LastOfNextC,
       Report.Nurse,
       (SELECT TOP 1 Brand
        FROM Report
        ORDER BY Brand DESC) AS LastOfBrand,
       (SELECT TOP 1 Paste
        FROM Report
        ORDER BY Paste DESC) AS LastOfPaste,
       (SELECT TOP 1 Bag
        FROM Report
        ORDER BY Bag DESC) AS LastOfBag,
       (SELECT TOP 1 ACC
        FROM Report
        ORDER BY ACC DESC) AS LastOfACC,
       (SELECT TOP 1 BM
        FROM Report
        ORDER BY BM DESC) AS LastOfBM,
       (SELECT TOP 1 PM
        FROM Report
        ORDER BY PM DESC) AS LastOfPM,
       (SELECT TOP 1 Bimeh
        FROM Report
        ORDER BY Bimeh DESC) AS LastOfBimeh,
       Main.[Dead/ Heald Date],
       Main.[Operation Date]
FROM Main INNER JOIN Report ON Main.ID = Report.ID
GROUP BY Main.ID,
         Main.Name,
         Main.Family,
         Main.Mobile,
         Main.[Import Date],
         Main.Ostan,
         Main.City,
         Main.REP,
         Main.REP1,
         Main.ostan2,
         Main.City2,
         Main.Hospital,
         Main.Expert,
         Main.Status,
         Main.Type,
         Main.Time,
         Report.Nurse,
         Main.[Dead/ Heald Date],
         Main.[Operation Date];

我希望这证明是有帮助的。

如果您有任何问题,请随时回复。