All pastes #329388 Raw Edit

Untitled

public text v1 · immutable
#329388 ·published 2007-01-26 18:36 UTC
rendered paste body
SELECT
        0 as orderkey,
        history.mtype as mtype,
        history.clientid as clientid,
        ClientInfo.Firstname as firstname,
        ClientInfo.LastName as lastname,
        history.amount as amount,
        history.description as description,
        history.datereceived as datereceived
FROM history JOIN ClientInfo
ON history.clientid = clientinfo.clientid
UNION
SELECT * FROM (
	SELECT
		1 as orderkey,
		'' as mtype,
		null as clientid,
		'' as firstname,
		'' as lastname,
		SUM(history.amount) as amount,
		'total' as description,
		history.datereceived as datereceived
	FROM history JOIN ClientInfo
	ON history.clientid = clientinfo.clientid
	GROUP BY history.datereceived
) TMPTBL
ORDER BY datereceived,orderkey