Skip to content

Tag: sql-server

Removing count column from query output

Bsically, I’m trying to get the top 5 most rented but don’t want the actual count column as output only as a means of ordering the output. Is this possible? Answer You can try remove the count column and give the formula to order by part: My test: Select for MS SQL Server 2017: Output: col1 A B

SQL Server service can not execute in centos

I want to install SQL Server on centOs. I initial this service by command When I get status of service, I get this error: Failed to start Microsoft SQL Server Database Engine /var/opt/mssql/log/ I checked this location to see errors from SQL Server, but this location is empty. Can you help me? Answer Larnu, T…

SQL Join with partial string match

I have a table ‘TableA’ like: Another table ‘TableB’ like: I am using INNER JOIN between two tables like: I want to add another condition for join, which looks for value of ‘Group’ in ‘Subgroup’ and only joins if the ‘Group’ Value matches after &#821…

How to write SQL query without iterations

I have the following challenge: I have a table called hashtags_users_grouped which has the following structure: In each row, we find values that tell me when a certain user mentioned a certain hashtag and how many times he did it. In this example, user 1 mentioned hashtag 123 one time and 245 three times, whi…

SQL query GROUP BY groups

I have something like this: id name totalAmount 1 name1 10 2 name1 20 3 name1 25 4 name2 5 5 name2 12 And need to looks like this: id’s name totalAmount 1,2 name1 30 2,3 name1 45 1,3 name1 35 1,2,3 name1 55 4,5 name2 17 I’m using the STRING_AGG but don’t know how to separated in the first

Raw SELECT (without FROM) of most recent 7 days to current

I want to get the query result (e.g. to populate table) of last 7 dates (without times). I know that we can select some scalars without FROM statement. So I ended up with following solution: Please point me to better (and more elegant) solution if there is one. Answer The VALUES, table value constructor, is a…