Basic SQL Query Request
select employee_id , month , sum(working_hour) as [monthly total of working hour] from table_name group by employee_id, month
select employee_id , month , sum(working_hour) as [monthly total of working hour] from table_name group by employee_id, month
Answers (b) and (d) are totally wrong. The query won’t return any rows from TableA. If there are any matching rows are found in TableA, those rows get excluded by the condition in the WHERE clause. (Note that any value of columnName that satisfies the equality comparison in the ON clause will be non-NULL, and … Read more
Your current query structure cannot work! Your query returns when you have customers.total_orders = 1 because none of the left joins returns a set. As an example take one customer with 10 orders but only one containing the desired product. 1st three tables return 1 row, 1st LEFT JOIN returns 9 rows, 2nd 8 rows, … Read more
You could use the DATEADD function to get the desired result: SELECT * FROM table WHERE paydate >= DATEADD(month, -3, GETDATE()) AND credit < 10
Practically any database should be able to run such queries. In the case of SQL, using a simple WHERE … LIKE … condition with wildcards should be sufficient for simple cases. The interesting question will be how to scale this once you are dealing with much larger amounts of data, think YouTube for video portals. … Read more
ROUND documentation on MSDN select [raw] = 555.81, [rounded] = round(555.81, 0), [truncated] = round(555.81, 0, 1) Result: | raw | rounded | truncated | |——–|———|———–| | 555.81 | 556 | 555 | SQL Fiddle: http://sqlfiddle.com/#!6/9eecb7db59d16c80417c72d1/5290
SELECT TeamName, Count(TeamName) AS Count FROM table GROUP BY TeamName You need to use the Count Function – To count the team name And you need to use group by to determine how you want the counts to be grouped Edited Answer. SELECT TeamName, Count(DISTINCT CASE WHEN WorkInfo = 1 THEN SlNo end) AS Count1 … Read more
SAVEPOINT name– Marks a savepoint within the current transaction, there can be multiple savepoints in a transaction. ROLLBACK TO SAVEPOINT name -ROLLBACK TO SAVEPOINT rolls back the current transaction to the specified savepoint, so it discards any changes and or savepoints created after the savepoint to which you are rolling back. So in your problem, … Read more