相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

You should use the derived tables on your SQL. For example if you want to pick up the most recent row for an specific activity you're attempt to use:

select * 
from activities 
group by id_customer 
order by creation_date

but it doesn't work. Try instead:

SELECT * 
FROM ( select * 
       from activities 
       order by creation_date desc ) sorted_list 
GROUP BY id_customer

Default behaviour can not be changed, but you can use

SELECT * FROM foo GROUP BY bar ORDER BY bar DESC

without experiencing any speed penalties as the sorting will be performed on the grouped field anyway. By the way, when sorting is not important you can get (small) speed-up by using ORDER BY NULL.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章