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

  • Home
  • SEARCH
  • 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 6688837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:59+00:00 2026-05-26T05:26:59+00:00

I have a test database which logs data from when a store logs onto

  • 0

I have a test database which logs data from when a store logs onto a store portal and how long it stays logged on.

Example:
(just for visualizing purposes – not actual database)

Stores
Id  Description     Address         City
 1  Candy shop      43 Oxford Str.  London
 2  Icecream shop   45 Side Lane    Huddersfield

Connections
Id  Store_Ref   Start                    End
 1          2   2011-02-11 09:12:34.123  2011-02-11 09:12:34.123
 2          2   2011-02-11 09:12:36.123  2011-02-11 09:14:58.125
 3          1   2011-02-14 08:42:10.855  2011-02-14 08:42:10.855
 4          1   2011-02-14 08:42:12.345  2011-02-14 08:50:45.987
 5          1   2011-02-15 08:35:19.345  2011-02-15 08:38:20.123
 6          2   2011-02-19 09:08:55.555  2011-02-19 09:12:46.789

I need to get various data from the database. I’ve already gotten the max and average connection duration. (So probably very self-evident that..) I also need to have some information about which connection lasted the least. I ofcourse immediately thought of the Min() function of Linq, but as you can see, the database also includes connections that started and ended instantly. Therefore, that data isn’t actually “valid” for data analysis.

So my question is how to get the minimum value, but if the value = 0, get the next value that is the lowest.

My linq query so far (which implements the Min() function):

var min = from connections in Connections
          join stores in Stores
             on connections.Store_Ref equals stores.Id
          group connections
             by stores.Description into groupedStores
          select new
          {
             Store_Description = groupedStores.Key,
             Connection_Duration = groupedStores.Min(connections => 
                                             (SqlMethods.DateDiffSecond(connections.Start, connections.End)))
          };

I know that it’s possible to get the valid values through multiple queries and/or statements though, but I was wondering if it’s possible to do it all in just one query, since my program expects linq queries to be returned and my preference goes to keeping the program as “light” as possible.

If you have to great/simple method to do so, please share it. Your contribution is very appreciated! 🙂

  • 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-05-26T05:27:00+00:00Added an answer on May 26, 2026 at 5:27 am
    var min = from connections in Connections.Where(connections => (SqlMethods.DateDiffSecond(connections.Start, connections.End) > 0)
              join stores in Stores
                 on connections.Store_Ref equals stores.Id
              group connections
                 by stores.Description into groupedStores
              select new
              {
                 Store_Description = groupedStores.Key,
                 Connection_Duration = groupedStores.Min(connections => 
                                                 (SqlMethods.DateDiffSecond(connections.Start, connections.End)))
              };
    

    Try this, With filtering the “0” values you will get the right result, at least that is my taught.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have just 'migrated' an SQL Server 2005 database from DEVEL into TEST. Somehow
I have a script in PostgreSQL which restores test database from dump every night.
We have an WCF application which uses NHibernate to query data from the database.
When using Cucumber with Capybara, I have to load test database data from SQL
I have a test server that uses data from a test database. When I'm
I have a SqlServer database that I've manually filled with some test data. Now
I have the following data in my database (comma separated strings): word, test, hello
I have a test results database which has the following three tables along with
I have a database TEST, to which I connect at address 123.45.67.89:1521. How do
I have an Access database which is split, and have moved it from the

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.