select i.id, i.name, i.group_id, i.max_people, i.create_time, u.nick_name, w.shrimp, gb.total, gpo.order_total, gpo.rake_total, gpo.shell_total, gpo.consume_total from im_group_information i left join im_group g on g.group_id = i.group_id and g.admin=2 left join (select group_id, count(group_id) total from im_group where is_delete=0 group by group_id) gb on gb.group_id = i.group_id left join (select bid, count(bid) order_total, sum(rake) rake_total, sum(price) shell_total, count(distinct uid) consume_total from g_prop_order where is_delete=0 group by bid) gpo on gpo.bid = g.u_id left join u_user u on u.id = g.u_id left join u_wallet w on w.id = g.u_id left join (select uid, count(distinct uid) offline_total from u_online_log group by uid) l on g.u_id = l.uid where i.is_delete = 0;怎么查到im_group_information群组表中七天内登陆过的用户数量
时间: 2023-12-21 15:04:24 浏览: 140
可以使用子查询结合条件判断的方式来查询七天内登陆过的用户数量,具体实现如下:
```
SELECT COUNT(DISTINCT l.uid) AS login_total
FROM im_group_information i
LEFT JOIN im_group g ON g.group_id = i.group_id AND g.admin = 2
LEFT JOIN u_user u ON u.id = g.u_id
LEFT JOIN u_online_log l ON g.u_id = l.uid
WHERE i.is_delete = 0
AND l.login_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
```
这里使用了 `COUNT(DISTINCT l.uid)` 来统计七天内登陆过的用户数量,同时在 `WHERE` 子句中加入条件 `l.login_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)` 来筛选出七天内登陆过的用户。
相关问题
SYS.WRI$_ADV_OBJECTS锁表
SYS.WRI$_ADV_OBJECTS是Oracle数据库中的一个系统表,用于存储PL/SQL程序的编译信息。如果该表被锁定,可能是由于某些正在进行的PL/SQL编译过程导致的。如果你想知道是哪个会话锁定了该表,可以使用以下命令:
```
SELECT s.username, s.sid, s.serial#, l.locked_mode
FROM v$session s, v$lock l
WHERE s.sid = l.sid AND l.type = 'TM' AND l.id1 = (SELECT object_id FROM dba_objects WHERE owner = 'SYS' AND object_name = 'WRI$_ADV_OBJECTS')
```
这将返回锁定该表的会话的用户名、SID和序列号。如果需要,你可以终止该会话以释放表锁。但是在终止会话之前,请确保已经了解该会话正在进行的操作,以避免可能的数据丢失或其他问题。
把i2c.c 和 i2c.h写出来
以下是一个简单的I2C库函数的示例,包括i2c.c和i2c.h文件:
i2c.h:
```c
#ifndef __I2C_H__
#define __I2C_H__
#include "stm32f10x.h"
void i2c_init(void);
void i2c_write(uint8_t addr, uint8_t *data, uint16_t len);
void i2c_read(uint8_t addr, uint8_t *data, uint16_t len);
#endif /* __I2C_H__ */
```
i2c.c:
```c
#include "i2c.h"
#define I2C_SPEED 100000 // I2C总线速度,单位为Hz
void i2c_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // 使能GPIOB时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); // 使能I2C1时钟
// 配置GPIOB6和GPIOB7为复用推挽输出
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// 配置I2C1为标准模式,时钟速度为100kHz
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_ClockSpeed = I2C_SPEED;
I2C_Init(I2C1, &I2C_InitStruct);
I2C_Cmd(I2C1, ENABLE); // 使能I2C1
}
void i2c_write(uint8_t addr, uint8_t *data, uint16_t len)
{
uint32_t timeout = 0;
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY))
{
if (++timeout > 0x10000)
return;
}
I2C_GenerateSTART(I2C1, ENABLE);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
{
if (++timeout > 0x10000)
return;
}
I2C_Send7bitAddress(I2C1, addr << 1, I2C_Direction_Transmitter);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if (++timeout > 0x10000)
return;
}
while (len--)
{
I2C_SendData(I2C1, *data++);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
{
if (++timeout > 0x10000)
return;
}
}
I2C_GenerateSTOP(I2C1, ENABLE);
}
void i2c_read(uint8_t addr, uint8_t *data, uint16_t len)
{
uint32_t timeout = 0;
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY))
{
if (++timeout > 0x10000)
return;
}
I2C_GenerateSTART(I2C1, ENABLE);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
{
if (++timeout > 0x10000)
return;
}
I2C_Send7bitAddress(I2C1, addr << 1, I2C_Direction_Receiver);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if (++timeout > 0x10000)
return;
}
while (len--)
{
if (len == 0)
I2C_AcknowledgeConfig(I2C1, DISABLE);
timeout = 0;
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
if (++timeout > 0x10000)
return;
}
*data++ = I2C_ReceiveData(I2C1);
}
I2C_AcknowledgeConfig(I2C1, ENABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
}
```
需要注意的是,上述代码中的RCC_APB2PeriphClockCmd()、RCC_APB1PeriphClockCmd()和GPIO_Init()等函数需要根据具体的STM32开发板和引脚进行修改。同时还需要根据具体的I2C总线速度和使用的I2C模式来修改i2c_init()函数中的配置参数。
阅读全文