你好我有这个查询女巫工作正常
SELECT y,
CASE WHEN (v IS NULL) THEN 0 ELSE SUM(v.viewCount) END AS HIDDEN sumviewcount
FROM YTScraperBundle:YouTubeVideo y
LEFT JOIN y.allViews WITH v.firstFetch BETWEEN :fromDate AND :toDate
GROUP BY y ORDER BY sumviewcount DESC
这是由DQL生成的SQL
SELECT y0_.id AS id0, y0_.video_id AS video_id1, y0_.name AS name2, y0_.type AS type3, y0_.link AS
link4, y0_.first_fetch AS first_fetch5, y0_.last_fetch AS last_fetch6, CASE WHEN (v1_.id IS NULL)
THEN 0 ELSE SUM(v1_.viewCount) END AS sclr7 FROM youtubevideo y0_ LEFT JOIN views v1_ ON y0_.id
v1_.youtubevideo_id AND (v1_.first_fetch BETWEEN ? AND ?) GROUP BY y0_.id, y0_.video_id, y0_.name,
y0_.type, y0_.link, y0_.first_fetch, y0_.last_fetch ORDER BY sclr7 DESC LIMIT 30 OFFSET 0
我需要添加一个上面的LIKE子句,它首先对此进行排序。上面的查询运行正常,但它运行在所有YouTubeVideo的y上,如果我希望它只运行一些名称具有特定LIKE值的视频,我会在LEFT JOIN之后添加一个AND子句。
但我不知道在哪里添加它,如果我在:
之后添加它BETWEEN :fromDate AND :toDate
像这样:
BETWEEN :fromDate AND :toDate AND y.name LIKE '%somevalue%'
SQL呈现如下:
LEFT JOIN views v1_ ON y0_.id
v1_.youtubevideo_id AND (v1_.first_fetch BETWEEN ? AND ? AND y.name LIKE '%somevalue%')
我添加的条款不应该介于两者之间。它不应该在外面吗?
无论如何,我如何绕过BETWEEN的声明?我可以做到:
...MyComparison AND BETWEEN...
答案 0 :(得分:0)
尝试以下where子句
Where '2014-10-01'< Date_Column and '2014-11-01'>Date_column and name like '%abc%'