Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 行转列,列转行的代码是不是在tidb里面用不了?
|
username: Steve阿辉
Is the code for converting rows to columns and columns to rows not usable in TiDB?
Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 行转列,列转行的代码是不是在tidb里面用不了?
Is the code for converting rows to columns and columns to rows not usable in TiDB?
The PIVOT function for row-to-column transformation is only available in Oracle and PostgreSQL, right? MySQL doesn’t support it either.
It seems so. When I input this function in Navicat, it is not recognized.
It is recommended to use aggregate functions and case functions as a replacement:
SELECT
username,
SUM(CASE WHEN subject = 'Chinese' THEN score ELSE 0 END) AS "Chinese",
SUM(CASE WHEN subject = 'Math' THEN score ELSE 0 END) AS "Math",
SUM(CASE WHEN subject = 'English' THEN score ELSE 0 END) AS "English",
SUM(CASE WHEN subject = 'Biology' THEN score ELSE 0 END) AS "Biology"
FROM scores
GROUP BY username;
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.