2022-11-6

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <unistd.h>
typedef struct
{
    long mtype;
    char mtext[128];
} msgbuff;

int main(int argc, char const *argv[])
{
    key_t key = ftok("./", 2);
    if (key < 0)
    {
        perror("ftok");
        return -1;
    }

    int msgid = msgget(key, IPC_CREAT | 0777);
    if (msgid < 0)
    {
        perror("msgid");
        return -1;
    }

    msgbuff buff;
    buff.mtype = 1;
    strcpy(buff.mtext, "123456");

    if (fork()) //  翻转进程
    {
        while (1)
        {
            for (int i = 0; i < 6 / 2l; i++)
            {
                int temp = buff.mtext[i];
                buff.mtext[i] = buff.mtext[5 - i];
                buff.mtext[5 - i] = temp;
            }
            if (msgsnd(msgid, &buff, sizeof(buff.mtext), 0) < 0)
            {
                perror("msgsnd");
                return -1;
            }
            sleep(1);
        }
    }
    else // 打印进程
    {
        while (1)
        {
            if (msgrcv(msgid, &buff, sizeof(buff.mtext), 1, 0) < 0)
            {
                perror("msgrcv");
                return -1;
            }
            printf("%s\n", buff.mtext);
        }
    }

    return 0;
}

优化代码,并提供新脚本SELECT SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' AND is_new_customer = 1 THEN 1 ELSE 0 END) AS new_customer_count, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' AND is_new_customer = 0 THEN 1 ELSE 0 END) AS old_customer_count, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' AND is_new_customer = 1 THEN payment_amount ELSE 0 END) AS new_customer_payment_amount, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' AND is_new_customer = 0 THEN payment_amount ELSE 0 END) AS old_customer_payment_amount, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN category = 'A' THEN 1 ELSE 0 END ELSE 0 END) AS category_A_customer_count, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN category = 'A' THEN payment_amount ELSE 0 END ELSE 0 END) AS category_A_payment_amount, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN category = 'B' THEN 1 ELSE 0 END ELSE 0 END) AS category_B_customer_count, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN category = 'B' THEN payment_amount ELSE 0 END ELSE 0 END) AS category_B_payment_amount, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN product_id = 'P1' THEN 1 ELSE 0 END ELSE 0 END) AS product_P1_customer_count, SUM(CASE WHEN order_date BETWEEN '2022-10-31' AND '2022-11-11' THEN CASE WHEN product_id = 'P1' THEN payment_amount ELSE 0 END ELSE 0 END) AS product_P1_payment_amount FROM orders WHERE (order_date BETWEEN '2022-10-31' AND '2022-11-11') OR (order_date BETWEEN '2021-10-31' AND '2022-10-30' AND order_date NOT IN (SELECT order_date FROM orders WHERE order_date BETWEEN '2022-10-31' AND '2022-11-11')) OR (order_date BETWEEN '2021-11-12' AND '2022-10-30' AND order_date IN (SELECT order_date FROM orders WHERE order_date BETWEEN '2022-10-31' AND '2022-11-11'))
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值