Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my tabel name

---customer--
this contain "transaction_time" contain hour field


\\\\my sql

SQL
SELECT amountPaid,  HOUR(`transactionTime`) time_range
FROM `customer_bill`

GROUP BY HOUR(`transactionTime`)






////and my ans is

id | amount | time diff

1 | 200 | 6
2 | 234 | 8
3 | 234 | 9
4 | 349 | 10

////i want my ans and id is 1 to 100000 ////

id | amount | time diff

1 | 200 | 6
0 | 0 | 7------its missing hour
2 | 234 | 8
3 | 234 | 9
4 | 349 | 10
Posted
Updated 19-Nov-15 23:34pm
v2

1 solution

You can take help of CTE to do this.
I don't have much knowledge on MySQL but if you can translate T-SQL (SQL Server) to MySQL query then you can refer following T-SQL query -

SQL
DECLARE @tbl AS TABLE(n INT)

;WITH cte_demo(n) AS
(
    SELECT 1 AS n
        UNION ALL
    SELECT n + 1
        FROM cte_demo
        WHERE n < 1000
)
INSERT INTO @tbl SELECT * FROM cte_demo OPTION (MAXRECURSION 1000)


SELECT ISNULL(id,0) AS Id, ISNULL(amount,0) AS amount,ISNULL([time diff],n) 
FROM
(
	SELECT 1 id, 200 amount, 6 [time diff]
	UNION ALL
	SELECT 2 , 234 , 8
	UNION ALL
	SELECT 3 , 234 , 9
	UNION ALL
	SELECT 4 , 349 , 10
) t1
RIGHT JOIN @tbl t2 ON t2.n=t1.[time diff]


Hope, it helps :)

if you need further help please, let me know.
 
Share this answer
 
Comments
Member 12115149 22-Nov-15 23:18pm    
thxxx from help..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900