7

[Caleb SQL functions example]

 2 years ago
source link: https://gist.github.com/cameronbweston/55246b3f870c9ff47f637918b7c780ca
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Caleb SQL functions example] · GitHub

Instantly share code, notes, and snippets.

[Caleb SQL functions example]

select WebsiteProviders.websiteProviderId ,WebsiteProviders.name ,count(hostid) as totalhosts ,sum(activevdpcount) totalactivevdps ,avg(activevdpcount) as average ,min(ActiveVDPCount) as minimum ,max(ActiveVDPCount) as maximum from hosts inner join WebsiteProviders on hosts.WebsiteProviderId = websiteproviders.WebsiteProviderId -- things that happen before the group by where hosts.ActiveVDPCount >0

--the group by - how would you like to quality data? e.g. I want the sums and counts PER website provider group by WebsiteProviders.WebsiteProviderId,WebsiteProviders.name

--things that occur or otherwise could only be known after the grouping has been done having count(hostid) > 100 order by average desc


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK