如何使用标准 api 在 nhibernate 中按范围进行分组
我想在 Criteria api 中编写 sql:
SELECT CASE
WHEN total_pages = 0 THEN '0 pages'
WHEN total_pages BETWEEN 1 AND 3 THEN '1-3 pages'
WHEN total_pages BETWEEN 4 AND 6 THEN '4-6 pages'
WHEN total_pages > 6 THEN '7 + pages'
END AS pagerange, sum(total_pages) AS 'Total'
FROM dbo.connector_log_entry
GROUP BY
CASE
WHEN total_pages = 0 THEN '0 pages'
WHEN total_pages BETWEEN 1 AND 3 THEN '1-3 pages'
WHEN total_pages BETWEEN 4 AND 6 THEN '4-6 pages'
WHEN total_pages > 6 THEN '7 + pages'
END
ORDER BY pagerange
I have sql that i would like to write in Criteria api:
SELECT CASE
WHEN total_pages = 0 THEN '0 pages'
WHEN total_pages BETWEEN 1 AND 3 THEN '1-3 pages'
WHEN total_pages BETWEEN 4 AND 6 THEN '4-6 pages'
WHEN total_pages > 6 THEN '7 + pages'
END AS pagerange, sum(total_pages) AS 'Total'
FROM dbo.connector_log_entry
GROUP BY
CASE
WHEN total_pages = 0 THEN '0 pages'
WHEN total_pages BETWEEN 1 AND 3 THEN '1-3 pages'
WHEN total_pages BETWEEN 4 AND 6 THEN '4-6 pages'
WHEN total_pages > 6 THEN '7 + pages'
END
ORDER BY pagerange
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的类名为
ConnectorLogEntry
,并且映射到total_pages 列的属性名为TotalPages
。我欠你 ORDER BY 位,但你总是可以在客户端排序。
This assumes your class is called
ConnectorLogEntry
and the property mapped to the total_pages column is calledTotalPages
.I owe you the ORDER BY bit, but you can always sort client-side.