Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这种情况下的SQL(SQLite)查询?_Sql_Sqlite - Fatal编程技术网

这种情况下的SQL(SQLite)查询?

这种情况下的SQL(SQLite)查询?,sql,sqlite,Sql,Sqlite,有两张桌子 User ======== uid name Data ========= distance timeSpend isShow uid (FK) 我想获得以下城市距离的订单列表(DESC) 1 ) in a specific timeSpend Range 2 ) group by the uid (Only select the longest Distance) 3 ) only isShow 尝试了以下查询,但没有成功。谢谢你的帮助 SELECT User.name, D

有两张桌子

User
========
uid
name

Data
=========
distance
timeSpend
isShow
uid (FK)
我想获得以下城市距离的订单列表(DESC)

1 ) in a specific timeSpend Range
2 ) group by the uid (Only select the longest Distance)
3 ) only isShow
尝试了以下查询,但没有成功。谢谢你的帮助

SELECT User.name, Data.distance, Data.timeSpend
FROM FROM User,Data
WHERE id IN (
    SELECT MAX(distance) FROM Data GROUP BY uid WHERE isShow = true
    )
AND User.uid = Data.uid
ORDER BY Data.distance DESC

您必须用您喜欢的值填充
between
语句

SELECT u.name, MAX(distance) as max_distance
FROM User u
join Data d on u.uid = d.uid
WHERE isShow = 1
and d.timeSpend between 1 and 2
group by u.uid, u.uname
ORDER BY max_distance DESC