本文介绍了用于读取数据的SQL查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是我的桌子1 一个s_id YY MM DD 1080 20006 2013 04 06 1080 20006 2013 04 02 1080 20006 2013 04 09 1080 20006 2013 04 09 1080 20006 2013 05 13 1080 20006 2013 05 29 1080 20006 2013 05 30 1080 20006 2013 05 31 1080 20006 2013 06 01 1080 20006 2013 06 02 1080 20006 2013 06 03 1080 20006 2013 06 04 1080 20006 2013 06 05 1080 20006 2013 06 05 根据月份和日期查找计数。 i想要报告下面的格式。 s_id YY MM yesterDATE到yesterDATE到 10daysbackDATE data 20daysbackDATE data 20006 2013 04 0 0 20006 2013 05 3 3 20006 2013 06 6 6 我正在使用以下查询。但它无法检索10天的数据和20天的数据。只有我可以检索当月。 SELECT userid,SUM([值]) AS [Count],PacketCategory FROM ( SELECT userid,[ values ], CASE WHEN packetsNumbers> = 0 AND packetsNumbers< 10 THEN ' 0到9' WHEN packetsNumbers> = 10 AND packetsNumbers< 20 那么 ' 10 to 19' WHEN packetsNumbers> = 20 AND packetsNumbers< 30 那么 ' 20到29' WHEN packetsNumbers> = 30 AND packetsNumbers< 40 THEN ' 30 to 39' WHEN packetsNumbers> = 40 AND packetsNumbers< 50 THEN ' 40 to 49' END AS PacketCategory FROM @ tmp ) AS T GROUP BY userid,PacketCategory ORDER BY userid 解决方案 在这里,您得到了答案:用于检索从日期到10之前的数据的SQL查询日期。 [ ^ ] This is My table1 a s_id YY MM DD1080 20006 2013 04 061080 20006 2013 04 021080 20006 2013 04 091080 20006 2013 04 091080 20006 2013 05 131080 20006 2013 05 291080 20006 2013 05 301080 20006 2013 05 311080 20006 2013 06 011080 20006 2013 06 021080 20006 2013 06 031080 20006 2013 06 041080 20006 2013 06 051080 20006 2013 06 05Find count based on month and date.i want report in bellow format. s_id YY MM yesterDATE to yesterDATE to 10daysbackDATE data 20daysbackDATE data 20006 2013 04 0 0 20006 2013 05 3 3 20006 2013 06 6 6 i am using bellow query. but it can not retrieve 10 days back data and 20 days back data. only i can retrieving present month.SELECT userid, SUM([values]) AS [Count], PacketCategoryFROM ( SELECT userid, [values], CASE WHEN packetsNumbers>=0 AND packetsNumbers<10 THEN '0 to 9' WHEN packetsNumbers>=10 AND packetsNumbers<20 THEN '10 to 19' WHEN packetsNumbers>=20 AND packetsNumbers<30 THEN '20 to 29' WHEN packetsNumbers>=30 AND packetsNumbers<40 THEN '30 to 39' WHEN packetsNumbers>=40 AND packetsNumbers<50 THEN '40 to 49' END AS PacketCategory FROM @tmp ) AS TGROUP BY userid, PacketCategoryORDER BY userid 解决方案 Here you got your answers: sql query for retrieving data from date to before 10 dates .[^] 这篇关于用于读取数据的SQL查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 03:09