我有两张桌子:
reports:
date, uuid
warns:
date, uuid, active
date
是时间戳(2016-05-16 16:06:58),uuid
是用户标识符字符串,active
是布尔值。
我想显示每天有多少reports
和warns
条目。目前我有这个问题:
SELECT DATE(date) Date, count(*) Reports
FROM reports
GROUP BY DATE(date)
ORDER BY DATE(date) DESC
显示如下表格:
Date | Reports
-----------+---------
2016-07-05 | 192
2016-07-04 | 230
2016-07-03 | 227
但我也希望加入当天发生的warns
个条目数,但前提是它的active
列是TRUE
,所以我希望查询返回像这样的表:
Date | Reports | Warns
-----------+---------+-------
2016-07-05 | 192 | 47
2016-07-04 | 230 | 59
2016-07-03 | 227 | 56
我是MYSQL的新手,所以我还没有弄清楚我会怎么做。我在JOINS和UNIONS上搜索了一下但是不知道它们是否适用于我的案例。任何帮助将不胜感激。
答案 0 :(得分:0)
您可以使用相关查询:
SELECT DATE(reports.date) Date, count(*) Reports,
(SELECT COUNT(*) FROM warns
WHERE DATE(warns.date) = DATE(reports.date) and warns.active = 'TRUE') as warns_cnt
FROM reports
GROUP BY DATE(reports.date)
ORDER BY DATE(reports.date) DESC
答案 1 :(得分:0)
为了说明联盟你可以: -
float moveSpeed = 3f;
float rotationSpeed = 3f;
float attackThreshold = 3f; //distance within which to attack
float chaseThreshold = 10f; //distance within which to start chasing
float giveUpThreshold = 20f; //distance beyond which AI gives up
float attackRepeatTime = 1f; //time between attacks
bool attacking = false;
bool chasing = false;
float attackTime;
Transform target; //the enemy's target
Transform myTransform; //current transform data of the enemy
void Update()
{
//rotate to look at the player
float distance = (target.position - myTransform.position).magnitude;
if (chasing)
{
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
}
//move towards the player
if (chasing == true && attacking == false)
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
//give up if too far away
if (distance >= giveUpThreshold)
{
chasing = false;
// attacking = false;
}
//attack, if close enough, and if time is OK
if (distance <= attackThreshold && Time.time >= attackTime) //if attacking we want to stop moving
{
//attack here
bossAttack.Attack();
attackTime = Time.time + attackRepeatTime;
print("Attacking!");
attacking = true;
// anim.SetTrigger("AutoAttack");
chasing = false;
}
else
{
//not currently chasing.
//start chasing if target comes close enough
if (distance <= chaseThreshold) //if he gets to chase, and then you move out of range again, he won't chase again. he will only attack if comes into range again
{
chasing = true;
// attacking = false;
// print("Chasing!");
}
}
}
查询在子查询中创建REPORTS和WARNS列,然后在子查询外部进行求和。