2

私は T-SQL クエリを持っていますが、それを Android 用の SQLite に変換するのに苦労しています。同じテーブル名、フィールド名、テーブル構造、および関係があります。

SELECT
   F.fieldID,F.name,F.description,F.sizeHA,F.sizeA
   ,F.owner,F.annualRent,F.latitude,F.longitude
   ,F.Farm_farmID,F.isActive,F.deactivationDate,F.areas,
   (SELECT COUNT(DISTINCT LOWER(culture)) FROM Usages 
          WHERE Field_fieldID = F.fieldID
          AND YEAR(date) = (SELECT TOP 1 YEAR(date) FROM Usages 
                            ORDER BY Date DESC)
   ) as UsageCount
   ,(SELECT TOP 1 u.culture FROM Usages u WHERE u.Field_fieldID = F.fieldID 
      ORDER BY u.date desc) as culture
   ,(SELECT TOP 1 u.sort FROM Usages u WHERE u.Field_fieldID = F.fieldID 
      ORDER BY u.date desc) as sort 
FROM Fields as F INNER JOIN Usages s on s.Field_fieldID = F.fieldID 
GROUP BY F.fieldID,F.name,F.description,F.sizeHA,F.sizeA
,F.owner,F.annualRent,
F.latitude,F.longitude,F.Farm_farmID,F.isActive,F.deactivationDate,F.areas
4

1 に答える 1