如何在mysql

时间:2016-07-08 14:20:45

标签: mysql

我有一张包含以下数据的表

Region Market    Cluster   Dt-Accept Count
South  Karnataka Bangalore 23-05-2015 5
North  Delhi     NewDelhi  25-08-2015 3

我想要一个sql语句,它应该根据count中存储的数字重复行数。

Region Market    cluster   Dt-Accept  count
South  Karnataka Bangalore 23-05-2015 5
South  Karnataka Bangalore 23-05-2015 5
South  Karnataka Bangalore 23-05-2015 5
South  Karnataka Bangalore 23-05-2015 5
South  Karnataka Bangalore 23-05-2015 5
North  Delhi     NewDelhi  25-08-2015 3
North  Delhi     NewDelhi  25-08-2015 3
North  Delhi     NewDelhi  25-08-2015 3

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

试试这个

    SELECT Region,Market,cluster,Dt-Accept,count
    FROM Table1 T JOIN (
                        SELECT 0 No UNION ALL SELECT 1  UNION ALL SELECT 2  UNION ALL 
                        SELECT 3   UNION ALL SELECT 4  UNION ALL SELECT 5  UNION ALL
                        SELECT 6   UNION ALL SELECT 7  UNION ALL SELECT 8  UNION ALL
                        SELECT 9   UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL
                        SELECT 12  UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL 
                        SELECT 15
                       ) S ON T.count > S.No 

Fiddle Demo