mysql distinct或分组查询

时间:2015-10-30 15:46:02

标签: mysql

我有以下查询: -

Select
  PUB.oa_inthed.adcode As Address_Code,
  PUB.oa_intnom."due-date" As Commitment_Due_Date,
  PUB.oa_inthed.company As Company,
  PUB.oa_intnom.costcentre As Cost_Code,
  PUB.oa_inthed.currency As Currency,
  PUB.oa_inthed.description As Description,
  PUB.oa_inthed.docdate As Document_Date,
  PUB.oa_inthed."doc-id" As Document_Type,
  PUB.oa_intnom.expensecode As Expense_Code,
  PUB.oa_inthed.intid As Interface_Record_Key,
  PUB.oa_inthed.posted As "Posted?",
  PUB.oa_inthed.srcaccount As Source_Account,
  PUB.oa_inthed.docval As Value_Cur,
  PUB.oa_inthed.period As Period,
  PUB.oa_inthed.stat As Status
From
  PUB.oa_inthed Inner Join
  PUB.oa_intnom On PUB.oa_intnom.intid = PUB.oa_inthed.intid Inner Join
  PUB.oa_intextra On PUB.oa_intextra.intid = PUB.oa_intnom.intid
Where
  PUB.oa_inthed.company = 01 And
  PUB.oa_inthed.intid = 'XM618197%' And
  PUB.oa_intextra.rectype = 'REQHEAD'

并返回以下数据: -

enter image description here

如何为每个intid获得明确的行?

我正在使用MySQL。

欢迎所有建议

1 个答案:

答案 0 :(得分:0)

试试这个(未经测试):

var userSchema = new Schema({ firstname: String, lastname: String });

// assign a function to the "statics" object of our userSchema
userSchema.statics.create = function (userObject) {
    console.log('Creating user');
    // use Function.prototype.call() to call the Model.create() function with the model you need
    return mongoose.Model.create.call(this.model('User'), userObject);
};