我有这样的记录:
Trans_ID ITEM_NAME TOTAL_TRANS
101
一个
5
101
一个
5
101 b 5
101 c 5
101 b 5
102 a 3
102 c 3
102 c 3
等(aprox 270k记录)
我应该使用什么查询来实现这样:
Trans_ID ITEM_NAME VALUE TOTAL_TRANS
101
a 2/5 5
101
b 2/5 5
101
c 1/5 5
102
1/3 3
102
c 2/3 3
非常感谢
答案 0 :(得分:0)
试试这个
SELECT
`Trans_ID`,
`ITEM_NAME`,
CONCAT(count(*), '/', `TOTAL_TRANS`) AS VALUE,
`TOTAL_TRANS`
FROM mytable
GROUP BY `ITEM_NAME`, `Trans_ID`, `TOTAL_TRANS`
答案 1 :(得分:0)
你可以试试这个
SELECT Trans_ID, ITEM_NAME,
CAST(COUNT(*) AS varchar) + '/' + CAST(TOTAL_TRANS AS VARCHAR) AS VALUE,
TOTAL_TRANS
FROM mytable
GROUP BY Trans_ID, ITEM_NAME, TOTAL_TRANS
答案 2 :(得分:0)
我对您的列数据类型做了一些假设,但这适用于您提供的示例数据。
SELECT Trans_ID, ITEM_NAME,
convert(varchar(5), count(*)) + '/' + convert(varchar(5), TOTAL_TRANS) as [VALUE],
TOTAL_TRANS
FROM Trans
GROUP BY Trans_ID, ITEM_NAME, TOTAL_TRANS