表1的cuid不能重复
时间: 2024-04-08 20:28:53 浏览: 118
python 千万id不重复
如果你希望在表1中的cuid字段不能重复,你可以使用DISTINCT关键字来确保唯一性。修改后的查询语句如下:
```sql
SELECT t2.city_name, COUNT(*) AS count
FROM (
SELECT DISTINCT sub.cuid
FROM (
SELECT cuid, ROW_NUMBER() OVER (ORDER BY cuid) AS rn
FROM map_huiyan_short_stay
WHERE loc_x > 12993523 AND loc_x < 13012467 AND loc_y > 4773079 AND loc_y < 4789463 AND event_day = 20230605
) sub
WHERE rn = 1
) t1
JOIN (
SELECT cuid, city_name
FROM map_huiyan_long_stay_with_area
WHERE event_day = 20230605 AND event_type = 'home' AND event_os = 'android'
) t2 ON t1.cuid = t2.cuid
GROUP BY t2.city_name;
```
通过在子查询中使用DISTINCT关键字,可以确保在表1中的cuid字段不重复。
阅读全文