I know that if this is a one-count state, then how should it work. How can I work for this many situations?
select count (where DEVICENAME 'AR%' like TableName.DeviceName) DEVICE_Type_A, as the count (TableNamekDeviceName like where DEVICENAME '% R') as DEVICE_Type_B , (TableName.DeviceName where like DEVICENAME 'p%') count as DEVICE_Type_C, (TableName.DeviceName where DEVICENAME 'as DEVICE_Type_D AM% like'), count DB.TableName TableName where TableName.DURATIONMIN & gt; '180'
You must use the case statements!
as select count DEVICE_Type_A of calculation (when DEVICENAME 'AR%' the case of 1-end) (case when DEVICENAME 'R%' like the one at the end) DEVICE_Type_B as a result, the count (when DEVICENAME 'p%' in the case) DEVICE_Type_C like one end, (the case when DEVICENAME 'AM%' then 1 end) where counting such as DEVICE_Type_D the DB.TableName TableName TableName.DURATIONMIN & gt; '180' I have left the count. Personally, I think the "zodiac" is obvious:
SELECT sum (when device name 'AR%' then 1 and 0 end) DEVICE_Type_A, sum (case when like DEVICENAME as the 'R%' DEVICE_Type_B then 1 and 0 at the end), sum (case when the DEVICENAME 'P%' is 1 and 0 end) DEVICE_Type_C, the amount (as the device name "AM% ' Like if 1 and 0 end) DEVICE_Type_D FROM DB.TableName TableName where TableName.DURATIONMIN & gt; '180'
Comments
Post a Comment