[英]SQLite subquery select statement
I have two tables lets assume history and Favorites 我有两个表让我们假设历史和收藏夹
Favorites
schema is (id int primary key, isFav int) Favorites
架构是(id int主键,isFav int) History
schema is (id int) History
模式是(id int) Favorites
table has => songs with id and an int (0 or 1) and history table has => series of id which may be duplicates Favorites
表= =歌曲的id和一个int(0或1)和历史表有=>系列的id可能是重复的
I want a SQL statement for selecting ids from favorites which has value = 1 and order by number of occurrence(count) in history table (it may contain or not record with that id) 我想要一个SQL语句,用于从收藏夹中选择具有值= 1的id并按历史表中的出现次数(计数)排序(它可能包含或不包含该id的记录)
This should work for you: 这应该适合你:
SELECT
x.id
, (
SELECT
COUNT(y.id)
FROM y
WHERE y.id = x.id
) as YCount
FROM x
WHERE value = 1
ORDER BY YCount;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.