Skip to content

Tag: sql-server

How to extract Year together with Month from this query

I have a query to show total orders by month based on a date column. May I know how to append year to the Month column? Answer I would just aggregate directly by the year and month, as a single text field: If you really want the year and three letter abbreviation for the month, you may try:

SQL how to get the max date when already using max

I want to get the maximum f.post date, and then the maximum a.process date. When I try to use MAX(a.processdate), it won’t work because of the group by and the other MAX already used. This is my result so far: I want it to just return this: Note: a.processdate is an INT (I did not create the database th…

Sum data based on columns

Table 1 has several columns with distinct values. What I want is this information combined and condensed to the different column levels, so that the sale and value amounts are sum’d based on the product and type in the year and months instead of each distinct line being displayed as a separate value. For exam…

Create table from a table in SQL Server

Below is the query I tried to execute in SQL Server: I get this error: Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ‘(‘ I did some research on google to understand and isolate the error, but, failed to do so. Could anyone please help me understand the error. Thank you Answer SQL-Server…

Query using group by with steps/range over large data

I have a table that stores a sensor temperature readings every few seconds Sample data looks like this I want to have the average temperature per device so I ran the following query Where I can pass the time range I want. My issue is that this gives me total average but I want steps or range I want to