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
Tag: sql-server
Trigger in SQL causing error “Product_Reorder is not a recognized SET option”
I am not getting a syntax error syntax error near ; This is referring to the ; at the end of the code. Answer Not 100% sure what you’re trying to do – you’re not giving us much to go on, either! I’m assuming you mean you want to set a column called Product_ReOrder in your table to 1 if
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 ̵…
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…
Generate Scripts to move a database from one server to another
I want to move a database from our testing server to my local server. I don’t have the option of back up and restore since I don’t have permission. So I decided to use the generate script option to create all the scripts for the DB and then move over the database to my local server. The problem I&…
Join on existing aggregate query to pivot result without id
On a Sql-Server instance, I have three tables: ActionItem Id Name 1 Fish 2 Gravy 3 Pants ActionData Id ActionId Group Field Value 1 1 1 1 100 2 1 1 2 200 3 1 1 3 300 4 1 1 4 NULL 5 1 1 5 NULL 6 1 2 6 “Some Text” 7 2 1 1 50 8
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…
FOR XML PATH produces only first item
I have two tables: Reservations and ReservationNights (every reservation has many nights). In a stored procedure, I have a variable that looks like this: @roomTypeList = ‘2;3;4;5;’ -> its a list of RoomUseIds. I need to display only the reservations that have a reservation nights with one of th…