[Solved] SQL query a percentage [closed]

[ad_1] GROUP BY and HAVING Class 101 SELECT student_id, SUM(CAST(pass AS INT)) * 100 / COUNT(course_id) as pass_rate FROM MyTable GROUP BY student_id HAVING(sum(cast(pass as int)) * 100 / count(course_id)) > 95 [ad_2] solved SQL query a percentage [closed]

[Solved] 1 x chen hyd 2 y bang mum [closed]

[ad_1] Use UNION like: SELECT id,name,add1 from mytable UNION SELECT id,name,add2 from mytable EDIT: for better performance you can use UNION ALL instead, that will give you the same result: SELECT id,name,add1 from mytable UNION ALL SELECT id,name,add2 from mytable 4 [ad_2] solved 1 x chen hyd 2 y bang mum [closed]

[Solved] T-SQL | SQL-Server Pivot [closed]

[ad_1] Try: select Agent, max(case when `desc` = ‘Total’ then ColValue else 0 end) Total, max(case when `desc` = ‘Replaced’ then ColValue else 0 end) Replaced from tbl group by Agent Demo sqlfiddle 1 [ad_2] solved T-SQL | SQL-Server Pivot [closed]

[Solved] SQL Server : how to sum? [closed]

[ad_1] SELECT SUM(Value) FROM TableName; Using a GROUP BY (per your comment above) is when you want things grouped over a subset. In this case, a group by would return the same info you’ve sampled, because there’s no groups to sum on the desc field… however if you had two “e” descriptions (let’s say 40 … Read more

[Solved] How to improve performance of this query [closed]

[ad_1] Few ideas below Remove as many left joins as possible. Use inner joins where-ever possible. Remove sub-query to get ISerialNumber. Get this later in wrapper query. Create indexes on columns in the WHERE clause if not already existing. Do not use this way of date comparison. Imagine this conversion for every row in your … Read more

[Solved] Convert month and year columns to a date column with additional string concatination

[ad_1] Assuming your are using date and MSSQL2012+: SELECT UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’)) + ‘-‘ +RIGHT(CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)),2) M_DELIVERY , ‘DELIVERY FOR ‘ +UPPER( FORMAT(CONVERT(datetime, ‘2017-02-01′,121),’MMM’))+’ ‘+ CAST( YEAR( CONVERT(datetime, ‘2017-02-01’,121)) AS VARCHAR(4)) AS Description Other way(using numbers and not date): (you can change months name abbrev.) SELECT SUBSTRING(‘GENFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC’,1+(MONTH_NUMB-1)*3,3)+’-‘+ RIGHT(YEAR_NUMB,2) AS M_DELIVERY , … Read more

[Solved] Subquery returned more than 1 value. wrong if statement [closed]

[ad_1] You do not need any of these IF..ELSE statements or even the sub-queries in your select, what you are after, can be achieved with the following simple select query: CREATE PROC GET_ORDER_ACCOUNT_DETAILS @ORDERID INT AS BEGIN SET NOCOUNT ON; SELECT CASE WHEN od.calcType=”K” THEN od.price * od.kilo ELSE od.quant * od.price END as [AMOUNT] … Read more

[Solved] How to do the c# string.split() in oracle

[ad_1] Replace the prefixes you want to remove, then find the index of the first and second underscores and then find the substring between those two separators: Oracle Setup: CREATE TABLE your_table ( value ) AS SELECT ‘DUM_EI_AO_L_5864_Al Meena Tower’ FROM DUAL UNION ALL SELECT ‘EI_AE_L_5864_Al radha Tower’ FROM DUAL Query: SELECT value, SUBSTR( replaced_value, … Read more