SELECT SUM(SELECT people_num FROM bo_reception_process_record WHERE attend = 2) attend, SUM(SELECT people_num FROM bo_reception_process_record WHERE attend = 1) unattend, sum(SELECT people_num FROM bo_reception_process_record WHERE status = 10) consumerEntryNumber, sum(SELECT people_num FROM bo_reception_process_record WHERE status = 20) logisticsEntryNumber FROM `bo_reception_process_record` pr WHERE pr.delete_time = 0 AND pr.process_id = 1664162709840809986 请帮我修改成可执行sql
时间: 2023-10-09 10:17:25 浏览: 69
好的,以下是修改后的 SQL 语句:
```
SELECT
SUM(CASE WHEN attend = 2 THEN people_num ELSE 0 END) AS attend,
SUM(CASE WHEN attend = 1 THEN people_num ELSE 0 END) AS unattend,
SUM(CASE WHEN status = 10 THEN people_num ELSE 0 END) AS consumerEntryNumber,
SUM(CASE WHEN status = 20 THEN people_num ELSE 0 END) AS logisticsEntryNumber
FROM
bo_reception_process_record
WHERE
delete_time = 0 AND process_id = '1664162709840809986';
```
以上 SQL 语句中,使用了 `CASE WHEN` 函数对 `people_num` 进行了分类求和,分别计算了 `attend = 2`,`attend = 1`,`status = 10`,`status = 20` 四种情况下的总人数。同时,增加了 `delete_time = 0` 和 `process_id = '1664162709840809986'` 的筛选条件。您只需要将 `1664162709840809986` 替换成您想要筛选的 `process_id` 即可。
相关问题
bo_reception_process_record表中有process_id,attend,status,people_num字段,现在想根据process_id筛选出来的数据,获取到attend = 2时attend = 1时status = 10时status = 20不同状态下,计算people_num的总数,请帮我写一个sql
好的,以下是根据您的要求写的 SQL 语句:
```
SELECT
SUM(IF(attend = 1 AND status = 10, people_num, 0)) AS attend_1_status_10_num,
SUM(IF(attend = 1 AND status = 20, people_num, 0)) AS attend_1_status_20_num,
SUM(IF(attend = 2 AND status = 10, people_num, 0)) AS attend_2_status_10_num,
SUM(IF(attend = 2 AND status = 20, people_num, 0)) AS attend_2_status_20_num
FROM
bo_reception_process_record
WHERE
process_id = 'your_process_id' AND attend = 2;
```
以上 SQL 语句中,使用了 `IF` 函数对 `people_num` 进行了分类求和,分别计算了 `attend = 1` 且 `status = 10`,`attend = 1` 且 `status = 20`,`attend = 2` 且 `status = 10`,`attend = 2` 且 `status = 20` 四种情况下的总人数。同时,增加了 `attend = 2` 的筛选条件。您只需要将 `your_process_id` 替换成您想要筛选的 `process_id` 即可。
MD_STATUS SPI_MasterSend(uint8_t *const tx_buf, uint16_t tx_num) { MD_STATUS status = MD_OK; *tx_buf = (*tx_buf << 1) | 0x80; if (tx_num < 1U) { status = MD_ERROR; } else { SPI->SPIM |= _0040_SPI_RECEPTION_TRANSMISSION | _0008_SPI_BUFFER_EMPTY; /* transmission mode */ #ifdef SPI_WITH_DMA /* write transfer data with DMA */ DMAVEC->VEC[DMA_VECTOR_SPI] = CTRL_DATA_SPI; DMAVEC->CTRL[CTRL_DATA_SPI].DMACR = (0 << CTRL_DMACR_SZ_Pos) | (0 << CTRL_DMACR_CHNE_Pos) | (0 << CTRL_DMACR_DAMOD_Pos) | (1 << CTRL_DMACR_SAMOD_Pos) | (0 << CTRL_DMACR_MODE_Pos); DMAVEC->CTRL[CTRL_DATA_SPI].DMBLS = 1; DMAVEC->CTRL[CTRL_DATA_SPI].DMACT = tx_num - 1; DMAVEC->CTRL[CTRL_DATA_SPI].DMRLD = tx_num - 1; DMAVEC->CTRL[CTRL_DATA_SPI].DMSAR = (uint32_t)(tx_buf + 1); DMAVEC->CTRL[CTRL_DATA_SPI].DMDAR = (uint32_t)&SPI->SDRO; /* init DMA registers */ CGC->PER1 |= CGC_PER1_DMAEN_Msk; DMA->DMABAR = DMAVEC_BASE; DMA->DMAEN1 |= (1 << DMA_VECTOR_SPI % 8); #endif #ifdef SPI_WITH_DMA g_spi_tx_count = 1; /* send data count */ gp_spi_tx_address = tx_buf; /* send buffer pointer */ #else printf("3333333333333\n"); g_spi_tx_count = tx_num; /* send data count */ gp_spi_tx_address = tx_buf; /* send buffer pointer */ printf("gp_spi_tx_address==%p\n",gp_spi_tx_address); printf("4444444444444444\n"); #endif SPI_Start(); printf("........."); SPI->SDRO = *gp_spi_tx_address; /* started by writing data to SDRO */ printf("77777777777777777\n"); gp_spi_tx_address++; g_spi_tx_count--; } return (status); }解释一下这个代码
这段代码是一个SPI主机发送数据的函数。函数接收两个参数,一个是指向要发送数据的缓冲区的指针`tx_buf`,另一个是要发送的数据的数量`tx_num`。
首先,代码将缓冲区中的第一个数据做了一些处理,将其左移1位并将最高位置为1,然后赋值给原来的位置。这个操作可能是为了设置SPI传输的某些特殊标志位。
接下来,代码检查`tx_num`是否小于1,如果是,则将`status`设置为`MD_ERROR`,表示发送错误。否则,代码将设置SPI控制寄存器的相关位,使其进入传输模式。
接着,代码判断是否使用DMA进行数据传输。如果使用DMA,则进行一系列DMA相关的设置,并启动DMA传输。如果不使用DMA,则设置`g_spi_tx_count`为要发送的数据量,设置`gp_spi_tx_address`为要发送数据的指针。
然后,代码调用`SPI_Start()`函数开始SPI传输。
最后,代码将第一个要发送的数据写入SPI数据寄存器,并递增`gp_spi_tx_address`指针和递减`g_spi_tx_count`计数器,以便发送下一个数据。
最后,函数返回状态值`status`。
阅读全文