|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Query
Dear All,
I have one table ,suppost Table "A", In this table, there are 3 fileds (ID,VALUE,DATE) ID is Primary Key ( Identity ) Value is for insert 3 values (0,1,2) Date is for date/time value. For example, Everyday there are many new records insert into this table. And the value in value filed is changed depends on what value the users want to insert(0,1,2,) Only one value at a time. and Data field will be inserted their inserting time. I would like to write the query to get the record set to show how many of value 0, and 1 and 2 per day. It should be show like this: DATE | CountOfValue1 | CountOfValue2 | CountOfValue3 and I want to to show last 7 days Any help would be thankful QP |
|
#2
|
||||
|
||||
|
try this:
Code:
select thedate
, sum(case when thevalue = 0
then 1 else 0 end) as CountOfValue0
, sum(case when thevalue = 1
then 1 else 0 end) as CountOfValue1
, sum(case when thevalue = 2
then 1 else 0 end) as CountOfValue2
from TableA
where thedate between current_date - interval 7 day
and current_date
group by thedate
rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|