Skip to content

Instantly share code, notes, and snippets.

@josephwambura
Last active November 2, 2022 19:10
Show Gist options
  • Save josephwambura/1725f90ca16a506be4450db4af26f988 to your computer and use it in GitHub Desktop.
Save josephwambura/1725f90ca16a506be4450db4af26f988 to your computer and use it in GitHub Desktop.
Helpful Sql Scripts
select count(*) as [Count], Avg(Amount) as [Average], Sum(Amount)/2 as [Sum divided by 2] from dbo_OrderLineItems where OrderId in 
(
	select Id from dbo_Orders where CustomerId in 
	(
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID'
	) and (Cast(CreatedDate as date) between '01 June 2022' and '31 July 2022')
)

How do I select last 5 rows in a table without sorting?

select Name 
from (
    select top 5 Name 
    from MyTable 
    order by Name desc
) a 
order by Name asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment