我有一个基本表,希望从中解析一些数据。
现在我运行两个查询以获取所需的数据。
查询1(用于获取总数或tally_id的“数量”)
PartyEvent
在上面的示例中,我得到的结果是247
查询2
export class EventUtility {
// pick item based on JSON-friendly conditional notation
events: Array<PartyEvent | AppointmentEvent | MealEvent>
constructor(events: Array<PartyEvent | AppointmentEvent | MealEvent>) {
this.events = events;
}
earliestEvent(): PartyEvent | AppointmentEvent | MealEvent {
// determine earliest event in array and return it
return event;
}
}
这给了我每个'tally_id'的总数,例如
SELECT
count(*)
FROM
tally
WHERE
time >= '2019-02-25 00:00' AND time <= '2019-03-04 21:00';
是否有一种将两者结合在一起的方法,所以这是一个很好的无缝查询操作?我想查看块的总数,如上面的247所示,以及每种单独类型的块的总数。
感谢interwebz!
答案 0 :(得分:0)
使用SELECT tally_id,count(*)
FROM tally
WHERE time >= '2019-02-25 00:00' AND time <= '2019-03-04 21:00'
GROUP BY tally_id
union
SELECT 'total', count(*)
FROM tally
WHERE time >= '2019-02-25 00:00' AND time <= '2019-03-04 21:00'
组合两个查询
protected override void ApplyAbpConceptsForAddedEntity(EntityEntry entry, long? userId, EntityChangeReport changeReport)
{
CheckAndSetMustHaveUserIdProperty(entry.Entity, userId);
base.ApplyAbpConceptsForAddedEntity(entry, userId, changeReport);
}
private void CheckAndSetMustHaveUserIdProperty(object entryEntity, long? userId)
{
if (userId == null)
return;
if (!(entryEntity is IMustHaveUser))
{
return;
}
var entity = entryEntity.As<IMustHaveUser>();
entity.UserId = userId.Value;
}