How to pull in two columns within the same table that has the same column name?

Jenn W 0 Reputation points
2023-02-23T18:42:38.5833333+00:00

If you are pulling totals from same column under different Column Ids and want to pt them in the same row, but under two separate columns.

EX.
Select EMPLOYEE_ID,

SUM (TAXWAGES) AS TAX AMOUNT,

SUM( TAXWAGES AS ) STATE TAX

From TABLE A

WHERE DED CODE IN (1, 2, 3)

User's image

SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Jingyang Li 5,896 Reputation points Volunteer Moderator
    2023-02-23T18:52:01.31+00:00

    Select EMPLOYEE_ID,

    SUM (TAXWAGES) AS [TAX AMOUNT],

    SUM( TAXWAGES) AS [STATE TAX]

    From TABLE A

    WHERE [DED CODE] IN (1, 2, 3)

    GROUP BY EMPLOYEE_ID

    0 comments No comments

  2. Anonymous
    2023-02-24T01:39:02.9166667+00:00

    Hi @Jenn W

    From the query you gave an example, your query juxtaposes the EMPLOYEE_ID and the sum function, which will give an error and you need to group the EMPLOYEE_ID.

    Jingyang Li has given the modified query, you can try it.

    Best regards,

    Percy Tang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.