Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT COUNT #1339

Closed
Hell-Hope opened this issue Sep 10, 2021 · 2 comments
Closed

SELECT COUNT #1339

Hell-Hope opened this issue Sep 10, 2021 · 2 comments

Comments

@Hell-Hope
Copy link

SELECT
user.id
(select count(*) from user_role where user_role.user_id = user.id)
FROM user

@Tapac
Copy link
Contributor

Tapac commented Sep 10, 2021

Something like below should work:

val subquery = UserRoleTable.slice(UserRoleTable.id.count()).select { UserRoleTable.userId eq UserTable.id }
val countExpression = wrapAsExpression<Long>(subquery)
UserTable.slice(UserTable.id, countExpression).selectAll()

@mjjabarullah
Copy link

SELECT a.message_id, a.sent_from, a.sent_to, a.message, a.seen,
users.username, users.user_image,
b.unread_messages
FROM messages a
INNER JOIN
(SELECT sent_from,
max(message_id) AS maxid,
COUNT(CASE WHEN seen = 'NO' THEN 1 ELSE NULL END) AS unread_messages
FROM messages
GROUP BY sent_from, sent_to) AS b ON a.message_id = b.maxid
INNER JOIN users ON users.user_id = a.sent_from
WHERE a.sent_to = 5

how to write this query using this framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants