Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:35:06+00:00 2026-06-02T06:35:06+00:00

I am just starting learn SQL at work, but I am having trouble with

  • 0

I am just starting learn SQL at work, but I am having trouble with subquerys.
I am hoping for not just a Query, but an explanation of how to create subqueries.

Current SQL Query

SELECT to_char(P_DT, 'yyyy-mm-dd HH:mi:ss'), COUNT, LATENCY 
FROM latency ORDER BY P_DT

Returns

to_char(P_DT, 'yyyy-mm-dd HH:mi:ss'), COUNT, LATENCY
2012-04-20 03:42:00     83659   1m
2012-04-20 03:42:00 70305   2m
2012-04-20 03:42:00 105194  4m
2012-04-20 03:43:00 70277   1m
2012-04-20 03:43:00 0   2m
2012-04-20 03:43:00 0   4m

What I need

to_char(P_DT, 'yyyy-mm-dd HH:mi:ss'), COUNT.LATENCY='1m', COUNT.LATENCY='2m', COUNT.LATENCY='4m'
2012-04-20 03:42:00 83659       70305      105194
2012-04-20 03:43:00 70227       0          0

Thanks

Database has 3 columns: Timestamp, Count, Latency Type

Tmestamp = progressive timestamp for each min
Count = count, just a number
Latency Type = 1m, 2m or 4m

Each timestamp has a 1m, 2m, and 4m latency but these are all different rows.

I need to return one row that is
timestamp, count for 1m at timestamp, count for 2m at timestamp, count for 4m at timestamp

I can’t change the database to instead of count1m column count2m column etc.

A different way of looking at it is merging these three queries into one

SELECT to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\'), COUNT 
FROM LATENCY 
WHERE SOURCE_ID=\'2\' AND LATENCY = \'1m\' 
GROUP BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\') 
ORDER BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\')

SELECT to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\'), COUNT 
FROM LATENCY 
WHERE SOURCE_ID=\'2\' AND LATENCY = \'2m\' 
GROUP BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\') 
ORDER BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\')

SELECT to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\'), COUNT 
FROM LATENCY 
WHERE SOURCE_ID=\'2\' AND LATENCY = \'4m\' 
GROUP BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\') 
ORDER BY to_char(P_DT, \'yyyy-mm-dd HH:mi:ss\')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:35:09+00:00Added an answer on June 2, 2026 at 6:35 am

    If I understood you correctly, this should do it:

    SELECT  to_char(P_DT, 'yyyy-mm-dd HH:mi:ss'), 
            SUM(CASE WHEN LATENCY = '1m' THEN COUNT ELSE 0 END) AS LATENCY1m, 
            SUM(CASE WHEN LATENCY = '2m' THEN COUNT ELSE 0 END) AS LATENCY2m, 
            SUM(CASE WHEN LATENCY = '4m' THEN COUNT ELSE 0 END) AS LATENCY4m
    FROM latency 
    GROUP BY to_char(P_DT, 'yyyy-mm-dd HH:mi:ss')
    ORDER BY to_char(P_DT, 'yyyy-mm-dd HH:mi:ss')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting to learn intel assembly and I'm having trouble with this simple
I'm just starting to learn T-SQL and could use some help in understanding what's
I'm just starting to learn asp.net mvc and I'm not sure what the right
First, I'm just starting to learn MySQL with PHP. My query copy/paste directly from
just starting to learn Dojo, and I am having a heck of a time
I'm just starting to learn more advanced SQL along with PHP and I'm really
I'm just starting to learn C# and ASP.NETMVC, but every example I've found puts
I am just starting to learn Silverlight, not too familiar with Markup languages, nor
I'm just starting to learn web dev, but got myself a bit confused when
I'm just starting to learn to use HashMap and reading the java tutorial, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.