Aggregate functions

Hibernate ORM - A Quick Start Guide Hibernate Query Language (HQL)
1 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€47.65
List Price:  €66.72
You save:  €19.06
£39.75
List Price:  £55.66
You save:  £15.90
CA$69.76
List Price:  CA$97.68
You save:  CA$27.91
A$76.72
List Price:  A$107.42
You save:  A$30.69
S$67.33
List Price:  S$94.27
You save:  S$26.93
HK$388.98
List Price:  HK$544.61
You save:  HK$155.62
CHF 44.44
List Price:  CHF 62.21
You save:  CHF 17.77
NOK kr552.21
List Price:  NOK kr773.14
You save:  NOK kr220.92
DKK kr355.46
List Price:  DKK kr497.67
You save:  DKK kr142.21
NZ$85.44
List Price:  NZ$119.62
You save:  NZ$34.18
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳5,939.10
List Price:  ৳8,315.22
You save:  ৳2,376.11
₹4,213.04
List Price:  ₹5,898.59
You save:  ₹1,685.55
RM222.55
List Price:  RM311.59
You save:  RM89.04
₦84,406.11
List Price:  ₦118,175.31
You save:  ₦33,769.20
₨13,801.73
List Price:  ₨19,323.52
You save:  ₨5,521.79
฿1,732.09
List Price:  ฿2,425.07
You save:  ฿692.97
₺1,728.86
List Price:  ₺2,420.55
You save:  ₺691.68
B$292.03
List Price:  B$408.86
You save:  B$116.83
R902.23
List Price:  R1,263.20
You save:  R360.96
Лв93.33
List Price:  Лв130.67
You save:  Лв37.34
₩70,055.22
List Price:  ₩98,082.92
You save:  ₩28,027.69
₪183.99
List Price:  ₪257.61
You save:  ₪73.61
₱2,950.89
List Price:  ₱4,131.49
You save:  ₱1,180.59
¥7,719.70
List Price:  ¥10,808.21
You save:  ¥3,088.50
MX$1,019.17
List Price:  MX$1,426.92
You save:  MX$407.75
QR182.09
List Price:  QR254.95
You save:  QR72.85
P678.99
List Price:  P950.64
You save:  P271.65
KSh6,481.20
List Price:  KSh9,074.20
You save:  KSh2,593
E£2,480.36
List Price:  E£3,472.70
You save:  E£992.34
ብር6,084.35
List Price:  ብር8,518.58
You save:  ብር2,434.22
Kz45,607.24
List Price:  Kz63,853.79
You save:  Kz18,246.54
CLP$49,495.04
List Price:  CLP$69,297.02
You save:  CLP$19,801.98
CN¥362.27
List Price:  CN¥507.21
You save:  CN¥144.94
RD$2,995.34
List Price:  RD$4,193.72
You save:  RD$1,198.37
DA6,698.21
List Price:  DA9,378.03
You save:  DA2,679.82
FJ$113.66
List Price:  FJ$159.14
You save:  FJ$45.47
Q385.78
List Price:  Q540.13
You save:  Q154.34
GY$10,455.70
List Price:  GY$14,638.82
You save:  GY$4,183.11
ISK kr6,934.11
List Price:  ISK kr9,708.31
You save:  ISK kr2,774.20
DH502.94
List Price:  DH704.15
You save:  DH201.21
L913.81
List Price:  L1,279.41
You save:  L365.59
ден2,935.13
List Price:  ден4,109.41
You save:  ден1,174.28
MOP$398.48
List Price:  MOP$557.91
You save:  MOP$159.42
N$896.87
List Price:  N$1,255.69
You save:  N$358.81
C$1,828.79
List Price:  C$2,560.45
You save:  C$731.66
रु6,712.09
List Price:  रु9,397.46
You save:  रु2,685.37
S/188.45
List Price:  S/263.85
You save:  S/75.39
K200.10
List Price:  K280.16
You save:  K80.05
SAR187.68
List Price:  SAR262.77
You save:  SAR75.08
ZK1,372.96
List Price:  ZK1,922.26
You save:  ZK549.29
L237.18
List Price:  L332.07
You save:  L94.89
Kč1,207.21
List Price:  Kč1,690.20
You save:  Kč482.98
Ft19,630.30
List Price:  Ft27,483.99
You save:  Ft7,853.69
SEK kr549.29
List Price:  SEK kr769.05
You save:  SEK kr219.76
ARS$50,200.78
List Price:  ARS$70,285.11
You save:  ARS$20,084.33
Bs345.34
List Price:  Bs483.50
You save:  Bs138.16
COP$217,970.90
List Price:  COP$305,176.71
You save:  COP$87,205.80
₡25,315.87
List Price:  ₡35,444.24
You save:  ₡10,128.37
L1,255.96
List Price:  L1,758.45
You save:  L502.48
₲388,002.60
List Price:  ₲543,234.69
You save:  ₲155,232.08
$U2,130.69
List Price:  $U2,983.14
You save:  $U852.45
zł206.52
List Price:  zł289.14
You save:  zł82.62
Already have an account? Log In

Transcript

Like SQL, hibernate also supports aggregate functions. For example, if I want to get the average price of the products in each category, or how many products are there in each category, we can use the functions like count, min max, sum and average. So to demonstrate the same, let's comment out this function call. And then I'm going to type here, get category voice, product count. We don't have this function, if you press Command one, or Ctrl one on Windows, you get this new function. I press tab, change this to package, delete the two, my SQL would be something like this, where I want the category dot category name.

And then I type your count of P from product p group by P dot category, dot category name Of course, we have to type here P dot, because the moment you use an alias for the product type, you have to use the alias to access each of those members. Now the query is ready. Once again, we are getting an array of a string and a number. So we have to follow the same method, we can actually copy the entire code from here, paste over here, save this run the same, and we should see the category wise product count listed out. So if you want to add even additional functions, for example, if I want to say here, average of P dot unit price, I should be able to get that as well. And we can print the same here by typing average equals to plus data I have to save it and run.

We should now see the average price along with the count

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.