Filter Database through 2 comboboxes

Category Image 101

Hi, I'm using a MDB database that i would like to filter based on selections made in 2 comboboxes.

say: cmbBase and cmbMix.
cmbBase connects to "Base"
cmbMix connects to "Mix"
I have use the automated database method in C#
Click Here

 private void BaseMixBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.BaseMixBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.DSBaseMixDataSet);

        }

        private void frmImport_Load(object sender, EventArgs e)
        {
//filter out doubles

                    cmbBase.DataSource = DSBaseMixDataSet.BaseMix.Select(x => x.Base).Distinct().ToList();


        }

The problem is that i have no idea how i can filter the other combobox in such a way that it only shows the data in the next row of the selcted combobox.

So if i select "A" in cmbBase, cmbMix should only show the values "A+1; A+3; A+6" if there were only a few values i could use an if function, but this is a database with a lot of numbers. I tried many of the solutions i found, but none of them work as i expected. Anyone that can help me out here?

Auto_Explain: How to Log Slow Postgres Query Plans Automatically

Category Image 101

Do you want to know why a PostgreSQL query is slow? Then EXPLAIN ANALYZE is a great starting point. But query plans can depend on other server activity, can take a while to run, and can change over time, so if you want to see the actual execution plans of your slowest queries, auto_explain is the tool you need. In this post, we’ll look into what it does, how to configure it, and how to use those logs to speed up your queries.

What Is Auto_Explain?

Auto_explain is a PostgreSQL extension that allows you to log the query plans for queries slower than a (configurable) threshold. This is incredibly useful for debugging slow queries, especially those that are only sometimes problematic. It is one of the contribution modules, so it can be installed and configured easily on regular PostgreSQL.

Compare a table definition to function

Category Image 101

Hello. I am trying to check if a table definition (the default value on a constraint) is equal to UTC Time by using the following query:

IF NOT EXISTS((SELECT object_definition(default_object_id) AS definition
FROM sys.columns
WHERE name = 'ModifiedDate'
AND object_id = object_id('dbo.WorkflowAudit')) == GETUTCDATE())

However, you can not compare a function (GETUTCDATE()) to this Select Statement. I need to do it this way because I am building an update script and it can only update the table IF the table definition is NOT equal to UTC TIME Any ideas? Thank you

Get Net Income from Income and Expenditure Tables by Date

Category Image 101

I want to be able to write an SQL statement that pulls the sum of revenue and expenditure for each day and gets net income for each day with the distinct dates available in the Income and Expenditure tables. I have tried the following statement, but I'm not getting the desired result. I'm using MS Access.

SELECT
    Income.IncomeDate,
    SUM(Income.AmountPaid) AS IncomeAmount,
    Expenditure.ExpenseDate,
    SUM(Expenditure.TotalAmount) AS ExpenseAmount,
    IncomeAmount - ExpenseAmount AS NetIncome
FROM Income FULL OUTER JOIN Expenditure ON Income.IncomeDate=Expenditure.ExpenseDate
GROUP BY Income.IncomeDate
ORDER BY Income.IncomeDate

limit to 1 per where or clause

Category Image 101

I have managed to get blog posts displayed from each blog category but I want to limit it to 1 article from each blog category but unsure how to do it in the sql query I have, below is what I have so far

(SELECT BP.postID,postTitle,postSlug,postDesc,postDate,postImage
        FROM 
          blog_posts BP, blog_post_cats BPC 
    WHERE 
       BPC.catID = 6 AND BPC.postID = BP.postID OR BPC.catID = 5 AND BPC.postID = BP.postID OR BPC.catID = 4 AND BPC.postID = BP.postID OR BPC.catID = 1 AND BPC.postID = BP.postID
     )
    UNION
    (SELECT BP.postID,postTitle,postSlug,postDesc,postDate,postImage
        FROM 
          blog_posts BP, blog_post_cats BPC
    WHERE 
       BPC.catID = BPC.postID = BP.postID
     )

How to create a table in sql

Category Image 101

Create a table with following rules and regulations ma

1)Id should b identity
2)Name should allow only starting Letter with a to p
3)city should not allow Chennai,cbe, Salem
4) department should allo only cse,it,ece,
5) college default should b anna university
6) per should above only 70%
7) year of passing should be between 65 to 85
8) mailid should not allow null values
9)ph num should b primary key
10) designation should b unique constraints
11) salary default should b 0

How do I convert a SQLITE day number to a date string

Category Image 101

I have a SQLite database that for some insane reason stores dates as the number of days since 1899-12-31. I want to create a view that will display the date as an actual date. I can calculate a specific date from a specific day number as

select date('1899-12-31','Localtime','+44386 day') as dddd

which returns the single value '2021-07-09'. Unfortunately there seems to be no way to replace the hard coded number with the 'day' column. The original table also has the data broken down by hour (thus the GROUP BY clause), and by data_out and data_in (thus the SUM) So far I have

CREATE VIEW UsageByDay AS
SELECT day, SUM(data_in+data_out)/1024.0/1024.0 AS total 
  FROM usage GROUP BY day 
ORDER BY day DESC;

Which gives me on select

DAY     total
44386   45.2344284057617
44385   35.1123762130737
44381   26.000226020813
.
.
.

I want to replace the numerical values for day with the calculated date to give

DAY          total
2021-07-09   45.2344284057617
2021-07-08   35.1123762130737
2021-07-07   26.000226020813
.
.
.

Any suggestions on how to modify my CREATE VIEW query?

[Fixed] Database in Recovery Mode SQL Server 2014

Category Image 101

Summary

This post discusses the instances that put a SQL Server 2014 database in recovery mode and what causes the database to get stuck in recovery. Also, it discusses the methods to restore the database. 

You may find a SQL Server 2014 database in recovery mode when you restart the SQL Server service or restore a database from SQL Server Management Studio (SSMS). Also, a database goes into recovery mode if you restart a system abnormally. The database goes into recovery in such a scenario until all the active transactions are committed or rolled back. Let the recovery process complete, and the database comes back online.

How can I limit number of bookings in SQL where per month only 5 bookings

Category Image 101

I have three tables:

First table is 'user':

user_id  |    Name   |
----------------------
1234354  | Abu Bakar |           
2543353  | Ali       |    
3342342  | Aliza     |    
4234243  | Ali       |  
5234324  | Mike      |     


Second table is 'meeting':

meeting_id  | meeting_name  |  meeting_startDate  | meeting_endDate | room_name  |
----------------------------------------------------------------------------------
1           | Discussion 1  |     2021-05-29      |   2021-05-31    |   room 1   |
2           | Discussion 2  |     2021-06-01      |   2021-06-02    |   room 2   |
3           | Discussion 3  |     2021-05-02      |   2021-05-02    |   room 1   |
4           | Discussion 4  |     2021-05-03      |   2021-05-03    |   room 1   |
5           | Discussion 5  |     2021-05-04      |   2021-05-04    |   room 1   |


Third table is 'booking':

book_id  |  meeting_id  |  user_id  | 
-------------------------------------
0001     |      1       |  1234354  |
0002     |      2       |  1234354  |
0003     |      3       |  1234354  |
0004     |      4       |  1234354  |
0005     |      5       |  1234354  |

I want to allow per user can book each room_name up until 5 times for per month.

(Example: Abu Bakar can book room 1 only for 5 times per month). However, Abu Bakar should not able to booked room 1 for more than 5 times per month.

How can I write my query for above situation because I need to prepare SQL query for above so that it can help me to perform in my php if else statement?

Can someone assist me on this?
Note: As I know i agree there is insert, select, inner join and count involve but I just dont understand how to do the calculation for the date, place, and limitation for a user ID

Which transactions are deadlocked?

Category Image 101

Our database is running into problems, as many transactions are waiting for locks held by other transactions. Here is what each transaction is waiting for:

T1 is waiting on T4

T5 is waiting on T8

T2 is waiting on T7

T6 is waiting on T2

T3 is waiting on T2

T7 is waiting on T6

T4 is waiting on T1

T8 is not waiting

Which transactions are deadlocked?

Hypothetical Indexes in PostgreSQL

Category Image 011

In this blog, we will first cover what are hypothetical indexes and what is needed for these types of indexes. Secondly, we shall see the practical usage of these indexes. 

Need of Hypothetical Indexes:

As the name suggests, these are not real indexes, these are hypothetical indexes i.e. they are virtual indexes that PostgreSQL query planner does not consider when running queries.