Can someone tell me the advantage of using ActiveRecord vs writing a plain sql query?
Reference: EE Database Class User Guide
The database class (IE CodeIgniter's ActiveRecord, which really isn't ActiveRecord, reference) does some nicities for you, like escaping your queries automatically. It also allows you to reference your table names without using whatever Expression Engine table-name-prepending that occurs at install (usually something like "exp_table_name"). See the reference.
It definitely makes your code cleaner to read, and I only not use it when I have to do some seriously complex SQL stuff, like building multitable search queries. I recommend it for its code cleanliness highly.
Also what @johnathan-waters said. Although I feel that this wouldn't apply to ExpressionEngine as it is built around MySQL, and I do not know if you can easily switch DB adapters for an EE install.
From the CodeIgniter docs:
Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.