Question

  • Creator
    Topic
  • #2210791

    SQL join

    Locked

    by skatula ·

    Please how can I combine these select statements using a join and then insert the result into a new table.

    SELECT
    team, SUM(operations) as Operations_Completed
    from Table1
    where team in (‘bristol’, ‘leeds’, ‘newcastle’,’north west’)
    group by team

    SELECT

    team,
    SUM(sales) as Packsales,
    COUNT(*) as contacts,
    COUNT(CASE WHEN brandtype = ‘SOB’ THEN brandtype ELSE NULL END) as EffectiveContacts

    from Table2
    where team not in (‘MANCHESTER GREATER’,’MANCHESTER CITY’)
    group by team

All Answers

  • Author
    Replies
    • #2901159

      Clarifications

      by skatula ·

      In reply to SQL join

      Clarifications

    • #2901146

      Join wise there are two ways

      by tony hopkinson ·

      In reply to SQL join

      Create two temporary tables and select into them, then it should be just a join on team. Can’t tell from you request whether you want an inner or outer (left or right) though.

      The other way is a bit more sneaky
      and uses the following syntax
      select ….
      Join (select….) dummyTableName On Table1.Team = dummyTableName.Team

      Just prefix the either of the above with Insert into SomeTable if the table is alreday defined, or use select Into if not.

      HtHs

Viewing 1 reply thread