java - HQL version of a SQL join with group by -
I have two tables, bands and votes, the band has a name and an ID, and the total_vittas column and band near the votes .ID is a foreign key that points to band.id.
I have a lot of votes, have been saved in different dates. What I want to do is find the maximum value of the total_width column of each band, the following SQL query works:
select b.name, max (v.total_votes) In total, from band B, vote v where b.id = v.band_id group by total bn by b.name command;
The system I am working with, however, uses Hibernate I would like to rewrite that SQL query as HQL or as a hibernate parameter query.
Is it easy and I am missing it now? Thanks for any help.
In the HQL, you can try:
band Select the band.name, Max (vote vote total vote) included in the band. Vote by band. Order by maximum (vote.) << code> It assumes there is a one-to-many collaboration between
band
andvotes
( In fact, providing an object model is very useful when you work with the HQL and / or Criteria API to query the object model).In the case of the bus, here is the relevant part of the document:
A query that returns the total values returned to the class or components Any property should be grouped by:
select cat.color, cat (cat. Weight), cat cat group cat.color by count (cat) Choose foo.id, Foo.id
connecting to Fu Foo with average name (name), maximum (name) from foo.names name group. There are also one section that is allowed.
cat cat group ect Cat.color, sum (cat.weight), count (cats)cat.color in Cat.color from sel cat cat group (eg Col. TABBY, eg. Color)
are allowed by SQL functions and total work segments and in the order they are supported by the underlying database (i.e., Not in MySQL).
Cat selection of cat cat join cat in cat's name cat.id, cat.name, cat.other, cat.properties average (kitten weight. ) & Gt; The order described by the segment (kitten) asc, zodiac (kitten weighing)
By the section neither group nor segment can have arithmetical expressions in order. Being in hibernation does not currently extend a grouped unit, so if you have all the properties of the cat un-collected then you can not write a group by cat. You must list all non-collected properties explicitly.
Comments
Post a Comment