create report from an SQL query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Member
    • Aug 2025
    • 91

    #1

    create report from an SQL query?

    HI,

    I need to create a report or something I can use inside a layout from an SQL query and maybe PHP

    At this point, I want to just list all records linked to a primary_account_id, but in the future, I'd love to greatly expand on this

    This, for example, is the current query I want to use this time, though the option to use more advanced queries in the future would be a great help to me

    Code:
    select * FROM work_record wr where wr.account_id IN (SELECT id FROM account WHERE primary_account_id = '64ad54e22412eccc8');


  • item
    Active Community Member
    • Mar 2017
    • 1547

    #2
    Hi,
    have you advancedPack ?
    if yes, there are some sample like LeadsByLastActivity .... but you need "some level skill" because it's not easy to replicate/understand (for me i say).
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • jamie
      Member
      • Aug 2025
      • 91

      #3
      Originally posted by item
      Hi,
      have you advancedPack ?
      if yes, there are some sample like LeadsByLastActivity .... but you need "some level skill" because it's not easy to replicate/understand (for me i say).
      Hi item

      Yes, we do have the advancedPack, and I have been working as a web developer for years.

      Any got-ya's you'd warn me of before my adventure?
      Last edited by jamie; 09-25-2025, 08:11 AM.

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1316

        #4
        This is how i would do that

        PHP Code:
        $workRecords $this->entityManager
                        
        ->getRDBRepositoryByClass(WorkRecord::class)
                        ->
        where([
                            
        'accountId' => '64ad54e22412eccc8',
                        ])
                        ->
        find(); 

        Espocrm ORM and SelectBuilder are your friends here



        Last edited by rabii; 09-25-2025, 01:56 PM.
        Rabii
        Here to help :)

        Comment

        • jamie
          Member
          • Aug 2025
          • 91

          #5
          Originally posted by rabii
          This is how i would do that

          PHP Code:
          $workRecords $this->entityManager
          ->getRDBRepositoryByClass(WorkRecord::class)
          ->
          where([
          'accountId' => '64ad54e22412eccc8',
          ])
          ->
          find(); 
          rabii that looks so clean and integrated! Just where would you do it so i can put it into my report so i can put that at the bottom of a layout?

          Comment


          • rabii
            rabii commented
            Editing a comment
            can you explain more what you want to achieve ? i am not sure i fully understand. what do you mean by bottom of a layout ?
        • jamie
          Member
          • Aug 2025
          • 91

          #6
          rabii i am essentially just wanting to use some custom SQL in a report

          Comment


          • rabii
            rabii commented
            Editing a comment
            what do you mean by report mate ? is it report from advanced pack ?
        • jamie
          Member
          • Aug 2025
          • 91

          #7
          rabii yes, at the end of the day, i want to use SQL to determine which list is used for the display will be so much more powerful and simple than making up relationships and pivot tables

          Comment

        • jamie
          Member
          • Aug 2025
          • 91

          #8
          yes indeed, that looks like exactly what i am looking for

          Comment

          • jamie
            Member
            • Aug 2025
            • 91

            #9
            rabii thanks

            Comment


            • rabii
              rabii commented
              Editing a comment
              you are welcome
          Working...