SQL to codeIgnitor

am new to code igniter but am good in SQL, i need help on how i can write the following query in codeIgniter select sma_sales.date as date, sma_users.username, sum(sma_sale_items….

subcategory will not show as parent category

I am trying to get my subcategory based on the category here is my code