根据特定列中具有相同值的记录一次选择一组记录
我希望能够使用单个查询从表中选择特定列中具有相同值的所有记录。
澄清
条件: - document_id 不是主键。
列表 ids = SELECT DISTINCT T.document_id FROM 表 T;
列表块 = SELECT * from table where document_id = ids.next();
- 对块执行操作,然后检索下一个块
有人可以告诉我如何将这两个查询转换为单个查询吗?
更新
@Marco @StephanB 真的很抱歉我的问题太浮夸了...我应该学会更具体...
无论如何,我正在使用JAVA 和带有Torque 的Apache Turbine。 这是我想要更改的代码:
public void runQueue (String username, Customer customer) {
Criteria c = new Criteria();
c.add( DataEntryQueuePeer.CUSTOMER_ID, customer.getId());//DataEntryQueue.CUSTOMER_ID is not the primary key
c.add( DataEntryQueuePeer.STATUS, DataEntryQueue.STATUS_IN_KEYING );
c.add( DataEntryQueuePeer.DATA_ENTRY_USERID, username );
c.add( DataEntryQueuePeer.QUEUE_TYPE, Constants.CUSTOMER_QUEUE );
List<DataEntryQueue> v = DataEntryQueuePeer.doSelect( c );
if( v.size() > 0 ) {
//do something with v
v.setStatus(DataEntryQueue.STATUS_KEYING_COMPLETE);
v.setModified(true);
v.save();
}
}
我想在条件中添加一个字段(DataEntryQueuePeer.DOCUMENT_ID),以便在每个“doSelect”上仅选择具有相同 document_id 的记录。但没有将特定的 DOCUMENT_ID 传递给该方法。
如果我仍然不够清楚,请告诉我......谢谢。
I want to be able to use a single query to select all records out of a table having the same value in a particular column.
Clarification
Conditions:
- document_id is not a primary key.
List ids = SELECT DISTINCT T.document_id FROM table T;
List block = SELECT * from table where document_id = ids.next();
- perform operation on the block, then retrieve next block
Could anyone please tell me how to convert these two queries into a single query?
UPDATE
@Marco @StephanB really sorry that my question was so vauge...i should learn to be more specific...
anyway, i am using JAVA and Apache Turbine with Torque.
Here's the code which i want to change:
public void runQueue (String username, Customer customer) {
Criteria c = new Criteria();
c.add( DataEntryQueuePeer.CUSTOMER_ID, customer.getId());//DataEntryQueue.CUSTOMER_ID is not the primary key
c.add( DataEntryQueuePeer.STATUS, DataEntryQueue.STATUS_IN_KEYING );
c.add( DataEntryQueuePeer.DATA_ENTRY_USERID, username );
c.add( DataEntryQueuePeer.QUEUE_TYPE, Constants.CUSTOMER_QUEUE );
List<DataEntryQueue> v = DataEntryQueuePeer.doSelect( c );
if( v.size() > 0 ) {
//do something with v
v.setStatus(DataEntryQueue.STATUS_KEYING_COMPLETE);
v.setModified(true);
v.save();
}
}
I want to add one more field(DataEntryQueuePeer.DOCUMENT_ID) in the criteria so that only records with the same document_id are selected on every "doSelect". No specific DOCUMENT_ID is passed to the method though.
please let me know if i'm still not clear enough...thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 SQL 格式错误。正确的问题更有可能得到正确的答案。我将把你的表命名为 A 和 B。
Your SQL is malformed. A correct question is more likely to retrieve a correct answer. I'll name your table A and B.