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 8195323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:05:54+00:00 2026-06-07T05:05:54+00:00

I have this table: I need count the occurrence of the same line in

  • 0

I have this table: enter image description here

I need count the occurrence of the same line in column CloseTime and write the number of occurrences in the last column Count with where clause for Item and same account.

My single select for concrete Item and account is

SELECT CloseTime, COUNT(*) AS CloseTime
FROM Statement 
WHERE Account = 2013169 AND item = 'eurusd'
GROUP BY CloseTime
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC

It is possible to count in one update query?

  • 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-07T05:05:56+00:00Added an answer on June 7, 2026 at 5:05 am

    Depending on your use case, this is probably not a good idea. You would be better off creating “Count” as a calculated column or leaving it off the base table entirely and creating a view that included the count column. Also, I would generally avoid trying to have a column with a name that is also a reserved word, like Count.

    However, if you really want to do it, you can do it in one query. Just to make sure we are on the same page, I belive you were trying to group by only the closetime and the account and item will not be included in the group by (so, it will be counted if same close time and different item), but want to be able to update only the target account and item.

    In that case, it would look roughly like

    with cte1 as 
    (select 
    closetime, COUNT(*) as numCount
    from dbo.[statement]
    group by closetime)
    
    update dbo.[statement]
    set [count] = cte1.numCount
    from  dbo.[statement] as sd
    join cte1 
        on sd.closetime = cte1.closetime
    where
        sd.account = <your account num>
        and sd.item = <your item>
    

    EDIT:

    If I understand from the comments what you want correctly, then you could use a query like:

    with cte1 as 
    (select 
    closetime, COUNT(*) as numCount
    from dbo.[statement]
    group by closetime)
    
    select sd.*, --I normally  would advise not using * in production
    cte1.numCount as [Count]
    from statement as sd
    join cte1
       on sd.closetime = cte1.closetime
    where
            sd.account = <your account num>
            and sd.item = <your item>
    

    while this does use a CTE, it is a single SQL statement and will display the counts for the selected account num and item by their closetime.

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

Sidebar

Related Questions

I have a table like this Table A: Id Count 1 4 1 16
I'm stuck with a SQL Query. I have this table: [Reserve] ID NUMBER START_DATE,
I have a SQL table where I need to get the number for the
I need to have MySQL query like this one: UPDATE table_name SET 1 =
We have this current database which we need to replace some tables by anther
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table [Table 1] cid | arrived | date_arrived The [arrived field
I have this table, which can be seen as a basic custom gantt chart:

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.