Home > Mobile >  How to add alias column in SQL Table?
How to add alias column in SQL Table?

Time:10-01

I need some assistant. I have pursed the City name from the purchase address with the alias "City" . Now I have a I have a problem statement saying "Find the top cities with the highest sales" now, the city column is not into the main table so I cannot run a group by operation. How would I perform the Problem Statement?

Here is the pic of my tables

CodePudding user response:

If you're looking for a way to get the city with the highest number of Quantity_Ordered, you can try this.

Since your data table doesn't contain the city exactly but it needs to be parsed, it would probably be best to create a view.

CREATE VIEW vProductDataCity AS
SELECT *, PARSENAME... -- Fill the "..." with your parsing code

And then to get the top city:

SELECT TOP(1) city, SUM(Quantity_Ordered) as SumQuantity_Ordered
FROM vProductDataCity
GROUP BY city
ORDER BY SumQuantity_Ordered DESC;
  • Related