SELECT countMinute, dc, COUNT ( 1 ) FROM ( SELECT generate_series ( '2023-06-26' :: TIMESTAMP, '2023-06-30' :: TIMESTAMP, '1 hour' :: INTERVAL ) AS countMinute ) VA LEFT JOIN vc_user_equipment VUE ON countMinute >= VUE.create_time AND countMinute < sign_expiration_time WHERE good_id = 1 AND supplier_type = '2' GROUP BY countMinute,dc order by countminute
时间: 2024-04-07 16:33:22 浏览: 75
您的查询语句如下:
```sql
SELECT countMinute, dc, COUNT(1)
FROM (
SELECT generate_series('2023-06-26'::TIMESTAMP, '2023-06-30'::TIMESTAMP, '1 hour'::INTERVAL) AS countMinute
) VA
LEFT JOIN vc_user_equipment VUE ON countMinute >= VUE.create_time AND countMinute < sign_expiration_time
WHERE good_id = 1 AND supplier_type = '2'
GROUP BY countMinute, dc
ORDER BY countMinute
```
该查询语句的功能是统计在指定时间范围内(从2023年6月26日到2023年6月30日,每小时)符合条件的数据。在`vc_user_equipment`表中,根据`create_time`和`sign_expiration_time`字段的值与每个小时的时间范围进行比较,如果满足条件,则进行计数。最后,按照`countMinute`字段和`dc`字段进行分组,并按照`countMinute`字段进行升序排序。
阅读全文