startdate是日期格式为yyyy-MM-dd 如何传入日期区间 让这个SQL返回SUM后的结果
时间: 2024-04-08 12:34:52 浏览: 60
要在SQL查询中传入日期区间,您可以使用`BETWEEN`关键字来指定起始日期和结束日期。以下是修改后的查询示例:
```sql
SELECT * FROM (
SELECT '0' AS sskll, '0' AS bdkl, '0' AS lrykzs, '0' AS xzlryk, zrkll, (zrkll - zrsnkl) AS zrswkl, zrsnkl,
DATE_FORMAT(a.startdate, '%Y-%m-%d') AS startdate
FROM
(
SELECT persontimes AS zrkll, DATE_FORMAT(startdate, '%Y-%m-%d') AS startdate
FROM cz_jtxl_tourist_people_portrait
WHERE datatype = '100' AND areatype = '2'
AND startdate BETWEEN '起始日期' AND '结束日期' -- 替换为实际的起始日期和结束日期
GROUP BY startdate
) a
JOIN
(
SELECT SUM(persontimes) AS zrsnkl, DATE_FORMAT(startdate, '%Y-%m-%d') AS startdate
FROM cz_jtxl_tourist_people_portrait
WHERE datatype = '102' AND areatype = '2'
AND substring(srcareacode, 1, 2) = '43'
AND startdate BETWEEN '起始日期' AND '结束日期' -- 替换为实际的起始日期和结束日期
GROUP BY startdate
) c ON a.startdate = c.startdate
) tmp WHERE 1 = 1;
```
请将上述查询中的`'起始日期'`和`'结束日期'`替换为实际的起始日期和结束日期,以便传入日期区间。这样查询将返回指定日期区间内的SUM后的结果。
阅读全文