[英]MySql filter by multiple entries from same table
I have two tables: 我有两个表:
entries
id | entries
ID | name | 名称| entry
条目
filters
id | filters
ID | eid | 开斋节 name |
名称| value
值
In first table there are all posts stored and in the second one there is settings for each post. 在第一个表格中,所有帖子都已存储,在第二个表格中,每个帖子都有设置。 For example:
例如:
entries
contains 1 | entries
包含1 | First post | 第一篇文章| Lorem Ipsum
洛普伊普森
filters
contains filters
包含
1 | 1 | 1 |
1 | date_posted |
date_posted | 2013-06-19
2013-06-19
2 | 2 | 1 |
1 | author |
作者| admin
管理员
3 | 3 | 1 |
1 | view_count |
view_count | 578
578
I need to filter all posts where author is admin and view count is bigger than 300, how could I do it? 我需要过滤所有作者为admin且视图数大于300的帖子,该怎么办?
Try: 尝试:
SELECT e.id,
e.name,
e.entry
FROM entries e
LEFT JOIN filters a
ON a.eid = e.id
AND a.name = 'author'
LEFT JOIN filters v
ON v.eid = e.id
AND v.name = 'view_count'
WHERE a.value = 'admin'
AND v.value > 300
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.