English 中文(简体)
以书写 sql 查询的方式粘贴
原标题:Stuck in writing sql query

i have a table where termid,termversion are two primary key. column present in table - termid,termversion,name

我想选择所有名称为 % AB% 的术语, 结果应该包含每个匹配的术语, 并包含最大版本号 。

示例:

id    name   ver
1     ABBBB  1
1  ABBBB  2
1  ABBBB 3
2  ABC   1
2  ABC   2

输出应产生输出

1 ABBBB 3
2 ABC   2

I want to write this query in hibernate using Criteria...if any one can suggest me in hibernate then its really good else at least help me in writing the sql query. PS I am using postgresql

最佳回答

我认为这就是你们要找的:

SELECT id, name, MAX(ver)
  FROM table
 WHERE name ILIKE  %AB% 
 GROUP BY name, id        -- I assume: id == id  <==> name == name 

是吗?

问题回答

从 mytable 中选择 id, 名称, 最大( ver), 名称如% AB% 组 id, 名称

您可以尝试 sql 命令 。

从表名组的 id 中选择 id, name, max(ver), 名字类似% AB%





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签