Free for PREMIUM members
[Webinar] Streamline your web hosting managementRegister Today
create #table1 table (id int identity, ... yourother fields....)
select * from yourtable
select * from #table1
Open in new window
Say you have the following table and you want to add a column "num" as bellow:
type variety num
apple fuji 1
apple gala 2
apple limberwig 3
cherry bing 1
cherry chelan 2
orange navel 1
orange valencia 2
pear bartlet 1
pear bradford 2
Run the following query:
SELECT l.type, l.variety, count(*) as num
FROM Fruits l
left join fruits r on l.type = r.type and l.variety >= r.variety
group by l.type, l.variety
Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Join & Ask a Question
Join our community for more solutions or to ask questions.
For immediate help use Live now!