Is it possible to convert this SQL into a JOIN?
SELECT (SELECT t2.id
FROM items t2
WHERE t2.user_id = items.user_id
ORDER BY [a list of cols that aren't stated here]
LIMIT 1) AS id
FROM items
WHERE company_name = '....'
GROUP BY user_id
Why both? Just use FIRST_VALUE()
:
SELECT DISTINCT col3,
FIRST_VALUE(col4) OVER (PARTITION BY col3 ORDER BY col1)
FROM tbl
WHERE col2;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.