查询si3u3752.per_reg这个表的每位RYID的QSNY最小值
时间: 2024-03-20 11:40:40 浏览: 30
您使用如下 SQL 语句查询 `si3u3752.per_reg` 表中每位 `RYID` 的 `QSNY` 最小值:
```sql
SELECT RYID, MIN(QSNY) AS Min_QSNY
FROM si3u3752.per_reg
GROUP BY RYID;
```
这个语句会将 `si3u3752.per_reg` 表按照 `RYID` 分组,然后对每个分组中的 `QSNY` 取最小值,最后返回每个分组的 `RYID` 和对应的最小 `QSNY` 值。
相关问题
从si3u3752.per_reg a每个a.RYID最小的a.QSNY并用a.ryid关联biu.person b的b.RYID 然后用a.qsny-b.csrq
可以使用以下 SQL 语句实现该需求:
```
SELECT a.RYID, MIN(a.QSNY) AS QSNY, (a.QSNY - b.CSRQ) AS AGE_DIFF
FROM si3u3752.per_reg a
JOIN biu.person b ON a.RYID = b.RYID
GROUP BY a.RYID, b.CSRQ
```
该语句中,我们使用了 `JOIN` 连接 `si3u3752.per_reg` 和 `biu.person` 两张表,通过 `RYID` 字段进行关联。然后使用 `GROUP BY` 分组,以 `RYID` 和 `CSRQ` 为分组条件,计算每个员工最小的 `QSNY` 值以及 `QSNY` 和 `CSRQ` 之间的年龄差异。最后,使用 `SELECT` 语句选择需要展示的字段。
让他只返回一行数据update sddw.wyQ37520606_611 a set a.dwxydm = (select b.TYSHXYDM from biu.ORGN b, si3u3752.ORGN_reg c, SI3U3752.PER_DECL e, biu.person d WHERE a.sbjfsj = e.qsny and a.sfzjhm = d.yxzjhm and c.dwdjid = e.dwdjid and b.dwid = c.dwid and d.ryid = e.ryid);
To update only one row of data in the sddw.wyQ37520606_611 table, you can add a WHERE clause to the UPDATE statement to specify the condition that identifies the row you want to update. For example, if you want to update the row with the maximum value of the ID column, you can modify the statement as follows:
```
UPDATE sddw.wyQ37520606_611 a
SET a.dwxydm = (
SELECT b.TYSHXYDM
FROM biu.ORGN b, si3u3752.ORGN_reg c, SI3U3752.PER_DECL e, biu.person d
WHERE a.sbjfsj = e.qsny
AND a.sfzjhm = d.yxzjhm
AND c.dwdjid = e.dwdjid
AND b.dwid = c.dwid
AND d.ryid = e.ryid
)
WHERE a.ID = (
SELECT MAX(ID)
FROM sddw.wyQ37520606_611
);
```
In this statement, the WHERE clause filters the rows of the sddw.wyQ37520606_611 table to only update the row with the maximum value of the ID column. The subquery in the SET clause still returns a single value for that row.