Neo4j SKip, Limit, Merge and Aggregate

Skip Clause

 
  match(u:user) return u.name skip 2

Limit Clause

 
  match(u:user) return u.name limit 2

merge on create

 
  merge(e:employee{name:'new',add:'vellore'}) on create set e.joined='tod' return e

merge on match

 
  merge(c:clerk) ON MATCH set c.name='found' return c

merge with on create and on match

 
  merge(e:employee{name:'few',add:'vellore'}) on create set e.joined='now' on match set e.joined='already' return e

aggregate functions

 
  sum,min,max,avg,count
match(u:user) return sum(u.salary)
match(u:user) return max(u.salary)
match(u:user) return min(u.salary)
match(u:user) return avg(u.salary)
match(u:user) return count(u.salary)

Determing the count of node by label users in the database

 
  match(u:users) return count(*) as totalusers

Determine the total number of users from vellore

 
  match(u:user{address:'vellore'}) return count(*) as velloreusers

Determine the count of users from each address

 
  match(u:user) return u.address,count(*) as totaluser

Determine the total number of users who work for an organization by name VIT

 
  match(u:user)-[w:worksfor]->(o:organization{name:'VIT'}) return o.name,count(*) as totaluser

Determine total number of user from each organization

 
  match(u:user)-[w:worksfor]->(o:organization) return o.name,count(*) as totaluser

Order the count achieved in the previous question in the ascending order

 
  match(u:user)-[w:worksfor]->(o:organization) return o.name,count(*) as totaluser order by count(*)

Order the count achieved in the previous question in the descending order

 
  match(u:user)-[w:worksfor]->(o:organization) return o.name,count(*) as totaluser order by count(*) desc

Display the users who worksfor organization VIT and studied at college ceg

 
  match(c:college{name:'ceg'})<-[s:studied]-(e)-[w:worksfor]->(o:organization{name:'VIT'}) return c,s,e,w,o

Determine the count of users who worksfor VIT and also studied at CEG

 
  match(c:college{name:'ceg'})<-[s:studied]-(e)-[w:worksfor]->(o:organization{name:'VIT'}) return o.name,c.name,count(*) as totalusers

Determing the users who worksforVIT,studied at college Ceg and attended the school kpc

 
  match(c:college{name:'ceg'})<-[s:studied]-(e)-[w:worksfor]->(o:organization{name:'VIT'}) 
  match (e)-[a:attended]->(s1:school{name:'kpc'}) 
  return c,s,e,w,o,a,s1 

Aggregate functions on an employee database

 
 

Return the total count of Employees

 
  match(e:emp) return count(*) as totalcount

Return the max , min and sum of salary

 
  match(e:emp) return max(e.salary),min(e.salary),sum(e.salary)

returning count of male employees

 
  match(e:emp{gender:'male'}) return count(*)

return employees for every department

 
  match(e)-[w:worksfor]->(d) return d.name,count(*)

order the count in the ascending order

 
  match(e)-[w:worksfor]->(d) return d.name,count(*) order by count(*)